ArrayIndexOutOfBoundsException on Type.getType(String)
Many calls to the above method work properly; however the following two
scenarios cause an ArrayIndexOutOfBoundsException:
public void visitTryCatchBlock(Label start, Label end, Label handler, String
type) {
classVisitor.addReference(Type.getType(type)); // ERROR HERE
super.visitTryCatchBlock(start, end, handler, type);
}
...where type = java/lang/ClassNotFoundException. Full error code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 32
at org.objectweb.asm.Type.a(Unknown Source)
at org.objectweb.asm.Type.getType(Unknown Source)
at
analysis.dependencies.classrefs.ClassReferenceMethodVisitor.visitTryCatchBlock(ClassReferenceMethodVisitor.java:85)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at
analysis.dependencies.classrefs.ASMLocateClassReferencesCmdImpl.callExecute(ASMLocateClassReferencesCmdImpl.java:57)
at analysis.command.AbstractCommand.execute(AbstractCommand.java:26)
at
analysis.dependencies.classrefs.ASMLocateClassReferencesCmdImpl.main(ASMLocateClassReferencesCmdImpl.java:76)
And the other instance:
public void visitTypeInsn(int opcode, String desc) {
Type t = Type.getType(desc); // ERROR HERE
classVisitor.addReference(t);
super.visitTypeInsn(opcode, desc);
}
where desc = org/objectweb/asm/ClassReader. Full error code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 29
at org.objectweb.asm.Type.a(Unknown Source)
at org.objectweb.asm.Type.getType(Unknown Source)
at
analysis.dependencies.classrefs.ClassReferenceMethodVisitor.visitTypeInsn(ClassReferenceMethodVisitor.java:97)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at
analysis.dependencies.classrefs.ASMLocateClassReferencesCmdImpl.callExecute(ASMLocateClassReferencesCmdImpl.java:57)
at analysis.command.AbstractCommand.execute(AbstractCommand.java:26)
at
analysis.dependencies.classrefs.ASMLocateClassReferencesCmdImpl.main(ASMLocateClassReferencesCmdImpl.java:76)
I can't find the common thread between the two situations; both classes are
available on the class path (or ClassNotFoundException would have been
triggered earlier in the call sequence). Other calls to Type.getType(String)
work from other MethodVisitor methods (for example, I extract the return types
of all method calls using visitMethodInsn() and it works fine).
I'm using the Eclipse IDE, JDK 1.5.
The following code concisely reproduces the error:
import java.io.IOException;
import org.objectweb.asm.commons.EmptyVisitor;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
public class ASMReproduceError extends EmptyVisitor {
public MethodVisitor visitMethod(int access, String name, String desc,
String sig, String[] exc) {
return new ASMReproduceError();
}
public void visitTypeInsn(int opcode, String desc) {
System.out.println("Encountered type: "+ Type.getType(desc));
super.visitTypeInsn(opcode, desc);
}
public static void main(String[] args) throws IOException {
System.out.println("Finding types using visitTypeInsn()...");
ClassReader reader = new ClassReader("java.lang.Object");
reader.accept(new ASMReproduceError(), true);
}
}