Local variable end label in wrong position after ClassReader
Hi,
I am not sure if this is a bug or if I am misinterpreting some documentation.
When using the ClassReader to read some bytecode (from a class file that I am
sending in attachment) I get the end label of a local variable debug info in
the wrong position.
I use the following code for printing the one of its methods (with ASM 4.0):
ClassNode node = new ClassNode();
new ClassReader(new FileInputStream("NestedTryBlocks.class")).accept(node,
ClassReader.SKIP_FRAMES);
MethodNode m = node.methods.get(1);
Printer p = new Textifier();
TraceMethodVisitor v = new TraceMethodVisitor(p);
m.accept(v);
System.out.println(p.getText());
The problem lies in the label for the following variable:
...
, L10
, LINENUMBER 15 L10
, ALOAD 0
, BIPUSH 7
, PUTFIELD NestedTryBlocks.i : I
, L9
, LINENUMBER 17 L9
, ALOAD 0
, ALOAD 0
...
LOCALVARIABLE e1 Ljava/lang/Exception; L10 L9 2
I think that L9 should be between the last "ALOAD 0". If I use javap -p -v on
the same class, I get:
...
17: aload_0
18: bipush 7
20: putfield #22; //Field i:I
23: aload_0
24: aload_0
...
LocalVariableTable:
Start Length Slot Name Signature
...
17 6 2 e1 Ljava/lang/Exception;
According to the JVM spec (
http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#5956
), variable e1 should be defined between instructions at indices 17 and 23
(because it's 17 + 6 and the spec says that the end index is "inclusive").
Now, ASM documentation says that the end label is "exclusive" (see the
description of "end" in
http://asm.ow2.org/asm40/javadoc/user/org/objectweb/asm/tree/LocalVariableNode.html
), so this means that e1 is not defined at instruction 23.
It seems to me that the label for line number is interfering with the local
variable label.
Is this a bug, an optimization (because instruction 23 does not use e1) or am I
misinterpreting something?
Best regards,
Thiago
ps 1 - I tried using SKIP_DEBUG. The label remains there, but also in the wrong
place.
ps 2 - this class is part of the test classes for the quilt project (
http://sourceforge.net/projects/quilt/ )