I've just tried to change a behavior of a method: replace the return value:
ctMethod.insertBefore("return null;");
Transformation works perfectly, I even write clazz.toBytecode()
to a file and IntelliJ IDEA decompiles that .class
file successfully and I can see my change there.
However, there is a error that blocks retrasformation of the class, it seems it's thrown after my transformer is executed, it's in native code, and it doesn't have a message:
java.lang.VerifyError
at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:167)
at [place where I call retransformClasses]...
What does it mean? What am I doing wrong?
If I do ctMethod.insertBefore("System.out.println(1);");
instead, it starts to work.
Version of javassist is 3.26.0-GA
. The same happens on 3.27.0-GA
and on 3.27.0-GA-bugfix-328
.
setBody
(ctMethod.setBody("return null;");
) solves the problem: now I have nulls returned.