javassist
javassist copied to clipboard
javassist.CannotCompileException: [source error] no such class: $r
@chibash
Hi, I'm using javassist 3.22.0-GA. When I want to replace the result value using the code blow:
method.insertBefore("\nObject result = MyClass.replay(\"" + className + "\", \"" + method.getName() + "\", $args, $type);" + "\nif (result != null) return ($r)result; \n");
I get the exception below:
Exception in thread "main" javassist.CannotCompileException: [source error] no such class: $r at javassist.CtBehavior.insertBefore(CtBehavior.java:774) at javassist.CtBehavior.insertBefore(CtBehavior.java:734) at com.qunar.flight.ares.instrument.lib.ClassPoolTest.main(ClassPoolTest.java:27) Caused by: compile error: no such class: $r at javassist.compiler.MemberResolver.searchImports(MemberResolver.java:470) at javassist.compiler.MemberResolver.lookupClass(MemberResolver.java:414) at javassist.compiler.MemberResolver.lookupClassByName(MemberResolver.java:317) at javassist.compiler.MemberResolver.resolveClassName(MemberResolver.java:504) at javassist.compiler.TypeChecker.resolveClassName(TypeChecker.java:132) at javassist.compiler.TypeChecker.atCastExpr(TypeChecker.java:546) at javassist.compiler.JvstTypeChecker.atCastExpr(JvstTypeChecker.java:104) at javassist.compiler.ast.CastExpr.accept(CastExpr.java:55) at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:242) at javassist.compiler.CodeGen.compileExpr(CodeGen.java:229) at javassist.compiler.CodeGen.atReturnStmnt2(CodeGen.java:615) at javassist.compiler.JvstCodeGen.atReturnStmnt(JvstCodeGen.java:424) at javassist.compiler.CodeGen.atStmnt(CodeGen.java:363) at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50) at javassist.compiler.Javac.compileStmnt(Javac.java:567) at javassist.CtBehavior.insertBefore(CtBehavior.java:754) ... 2 more
I find the symbol $r in https://github.com/jboss-javassist/javassist/wiki/Tutorial-2, $r was used as the cast type in a cast expression, but it don't work. Why?
Waiting for your reply!
I'm hitting the same issue, any news @chibash on this? I can provide a reproducer easily
Can you kindly show test code? It's very helpful (saves my time, thanks) to check and fix the bug.