NPE in MethodRemapper with 'chop' stack map frames and tree API
Using ClassNode together with ClassRemapper causes an NPE. FrameNode#accept(MethodVisitor) passes null for the local array when calling visitFrame, and
MethodRemapper's implementation of visitFrame assumes the array is non-null.
===
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.commons.ClassRemapper;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.tree.ClassNode;
public class Test {
public static void main(String[] args) throws Exception {
ClassNode node = new ClassNode();
new ClassReader(Input.class.getName()).accept(node, 0);
node.accept(new ClassRemapper(new ClassWriter(ClassWriter.COMPUTE_MAXS), new
Remapper() {}));
}
private static final class Input {
public static int f() {
int x = 0;
for (int i = 0; i < 10; ++i) {
x++;
}
for (int i = 0; i < 10; ++i) {
x++;
}
return x;
}
}
}
===
Exception in thread "main" java.lang.NullPointerException
at
org.objectweb.asm.commons.MethodRemapper.remapEntries(MethodRemapper.java:97)
at org.objectweb.asm.commons.MethodRemapper.visitFrame(MethodRemapper.java:91)
at org.objectweb.asm.tree.FrameNode.accept(FrameNode.java:155)
at org.objectweb.asm.tree.InsnList.accept(InsnList.java:162)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:817)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:727)
at org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:412)
at Test.main(Test.java:14)