I just upgraded both DripStat and Chronon to ASM framework 5.0 to support Java 8. Apparently there is no migration guide for upgrading from asm 4 to asm 5 which caused a ton of issues.
Here is the list of those issues and their solutions so you don’t have to face them too:
1. Change to Opcodes.ASM5
Everywhere that you pass Opcodes.ASM4
, replace with Opcodes.ASM5
. This one is the most obvious.
2. Change onVisitMethodInsn() overrides
This one will cause you tons of subtle runtime bugs if you don’t know about it.
Issue:
ASM 5.0’s MethodVisitor
contains a new visitMethodInsn()
method with the signature:
void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf)
Note the addition of the last parameter boolean itf
which is to support default methods in Interfaces.
If you pass Opcodes.ASM5
, the MethodVisitor class will only call this method. So your pre asm 5 code that uses the visitMethodInsn()
method without the boolean itf
parameter will never be called! Of course, this means that your code will compile and you won’t even get a RuntimeException
. Just that since your visitMethodInsn()
is never called, you will have bugs in the instrumented code.
Solution:
Replace overrides to visitMethodInsn()
with the new version. Your IDE should be able to help you here by marking the previous version of the method as deprecated.
3. Changed your ClassNode subclasses
Do you have a class that extends from ClassNode like this:
class JSRInliningClassNode extends ClassNode { public JSRInliningClassNode() { super(); } }
This will cause a RuntimeException because ClassNode
’s no-arg constructor looks like this:
public ClassNode() { this(Opcodes.ASM5); if (getClass() != ClassNode.class) { throw new IllegalStateException(); } }
Solution:
Use the constructor that does take an argument, the code should be like this:
class JSRInliningClassNode extends ClassNode { public JSRInliningClassNode() { super(Opcodes.ASM5); } }
4. Use asm 5.0.1 atleast
ASM 5.0.1 was relased just a few days after the 5.0 release and contains some critical bugfixes. Make sure you use atleast that version.
Have fun!