Skip to content

Instantly share code, notes, and snippets.

@gfx
Last active August 29, 2015 14:00
Show Gist options
  • Save gfx/f8f2439ece61321e1208 to your computer and use it in GitHub Desktop.
Save gfx/f8f2439ece61321e1208 to your computer and use it in GitHub Desktop.

I'm trying to modify some code in static initializer with m.replace("$_ = ($r)false;"), but I got NPE:

Caused by: java.lang.NullPointerException
	at javassist.bytecode.ConstPool.getMethodrefNameAndType(ConstPool.java:418)
	at javassist.expr.MethodCall.getNameAndType(MethodCall.java:43)
	at javassist.expr.MethodCall.getMethodName(MethodCall.java:107)
	at com.github.gfx.javassistexamp.JavassistExample$2.edit(JavassistExample.groovy:29)
	at javassist.expr.ExprEditor.loopBody(ExprEditor.java:192)
	at javassist.expr.ExprEditor.doit(ExprEditor.java:91)
	at javassist.CtBehavior.instrument(CtBehavior.java:712)
	at javassist.CtBehavior$instrument.call(Unknown Source)

I guess it is because the static initializer has no method name, but ClassPool expects a method (behavior) should have a name.

ref. https://github.com/jboss-javassist/javassist/blob/master/src/main/javassist/bytecode/ConstPool.java#L418

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment