You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this issue is similar to fixed issue #328. I originally found the problem description on StackOverflow, please also read the related discussion.
The problem is inserting return null; into a method by insertBefore(). This fails in some cases, causing a VerifyError. A workaround is to insert if (true) return null; instead, then the error goes away. See here:
privatevoidreplaceReturnValue(CtClasstargetClass) throwsCannotCompileException {
// Fails in Javassist without ASM stack map repairStringinjectedCode = "return null;";
// Works in Javassist without ASM stack map repair// String injectedCode = "if (true) return null;";for (CtMethodctMethod : targetClass.getDeclaredMethods()) {
if (LOG_RETURN_VALUE_REPLACER) {
log("Replacing return value for method " + ctMethod.getLongName());
log("Injected code: " + injectedCode);
}
ctMethod.insertBefore(injectedCode);
}
}
If I repair the broken class Javassist produces via ASM, setting REPAIR_STACK_MAP_USING_ASM = true; in class JavassistMethodReturnValueReplacer, it works.
If you also set DUMP_CLASS_FILES = true, the sample program will output both the Javassist-generated, unrepaired class file and the ASM-repaired version. You can compare them using a byte code viewer and will notice differences in stack map frame generation, similar to #328.
The text was updated successfully, but these errors were encountered:
I think this issue is similar to fixed issue #328. I originally found the problem description on StackOverflow, please also read the related discussion.
Here is an MCVE reproducing the problem with both 3.27.0-GA and latest master 1c4e31b:
https://github.com/kriegaex/SO_Javassist_VerifyErrorReplacingMethodReturnValue_64561436
The problem is inserting
return null;
into a method byinsertBefore()
. This fails in some cases, causing aVerifyError
. A workaround is to insertif (true) return null;
instead, then the error goes away. See here:In some method bodies it works, e.g.
This one fails, though:
See class
TargetClass
.If I repair the broken class Javassist produces via ASM, setting
REPAIR_STACK_MAP_USING_ASM = true;
in classJavassistMethodReturnValueReplacer
, it works.If you also set
DUMP_CLASS_FILES = true
, the sample program will output both the Javassist-generated, unrepaired class file and the ASM-repaired version. You can compare them using a byte code viewer and will notice differences in stack map frame generation, similar to #328.The text was updated successfully, but these errors were encountered: