Community
Participate
Working Groups
When compiling following code with Eclipse complier (3.2 & 3.1.1) it is producing incorrect debug info for local variable "s". Sun javac compiler is working properly. This problem is apparent if breakpoint is set on the line with System.out and run in Eclipse debugger. Variable "s" is not listed in "variables" view and cannot be looked up in 'display' or 'expressions' either. public class TestA { public static void main(String[] args) { String s; if(args.length == 0) { s = "a"; } else { return; } System.err.println(s); } } Looking at bytecode produced by Eclipse compiler: public static main([Ljava/lang/String;)V L0 (0) LINENUMBER 10 L0 ALOAD 0 ARRAYLENGTH IFNE L1 L2 (4) LINENUMBER 11 L2 LDC "a" ASTORE 1 L3 (7) GOTO L4 L1 (9) LINENUMBER 14 L1 RETURN L4 (11) LINENUMBER 16 L4 GETSTATIC java/lang/System.err : Ljava/io/PrintStream; ALOAD 1 INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V L5 (15) LINENUMBER 17 L5 RETURN L6 (17) LOCALVARIABLE args [Ljava/lang/String; L0 L6 0 LOCALVARIABLE s Ljava/lang/String; L3 L1 1 and comparing it with bytecode from Sun's javac: public static main([Ljava/lang/String;)V L0 (0) LINENUMBER 10 L0 ALOAD 0 ARRAYLENGTH IFNE L1 L2 (4) LINENUMBER 11 L2 LDC "a" ASTORE 1 L3 (7) GOTO L4 L1 (9) LINENUMBER 14 L1 RETURN L4 (11) LINENUMBER 16 L4 GETSTATIC java/lang/System.err : Ljava/io/PrintStream; ALOAD 1 INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V L5 (15) LINENUMBER 17 L5 RETURN L6 (17) LOCALVARIABLE s Ljava/lang/String; L3 L1 1 LOCALVARIABLE args [Ljava/lang/String; L0 L6 0 LOCALVARIABLE s Ljava/lang/String; L4 L6 1 you can see that Eclipse bytecode is missing second range for variable "s" between labels L4 and L6
This is fixed in HEAD. I get: // Method descriptor #15 ([Ljava/lang/String;)V // Stack: 2, Locals: 2 public static void main(java.lang.String[] args); 0 aload_0 [args] 1 arraylength 2 ifne 11 5 ldc <String "a"> [16] 7 astore_1 [s] 8 goto 12 11 return 12 getstatic java.lang.System.err : java.io.PrintStream [18] 15 aload_1 [s] 16 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24] 19 return Line numbers: [pc: 0, line: 4] [pc: 5, line: 5] [pc: 11, line: 7] [pc: 12, line: 9] [pc: 19, line: 10] Local variable table: [pc: 0, pc: 20] local: args index: 0 type: java.lang.String[] [pc: 8, pc: 11] local: s index: 1 type: java.lang.String [pc: 12, pc: 20] local: s index: 1 type: java.lang.String Where the source is: 1:public class X { 2: public static void main(String[] args) { 3: String s; 4: if(args.length == 0) { 5: s = "a"; 6: } else { 7: return; 8: } 9: System.err.println(s); 10: } 11:} I will add a regression test for it.
Thanks Oliver, that was quick. Is there a chance to backport this to 3.1x stream? Of course if there will be maintenance builds...
Maybe. Adding Philippe in CC. Philippe, candidate for 3.1.3 or 3.1.2?
I believe this has been fixed in the same time I added the support for stack map table attribute. I tried with 3.2M4 and I could reproduce the failure. v_632 is still failing, but v_633 that contains the changes for the stack map table attribute doesn't have the problem anymore.
Added regression test org.eclipse.jdt.core.tests.compiler.regression.DebugAttributeTest.test001
Closing as FIXED. Philippe, let me know if you want it to be backported.
What would it involve for 3.1.x ? The stackmaptable attribute is not intended to be part of the 3.1.x.
(In reply to comment #7) > What would it involve for 3.1.x ? The stackmaptable attribute is not intended > to be part of the 3.1.x. This bug is about incorrectly generated debug info for local variables
I could simply extract the part of the changes for the stack map table that involved the if statement. No need to backport all the changes.
Verified for 3.2 M5 using build I20060215-0010