Community
Participate
Working Groups
Using this class, put a conditional breakpoint on the "s = i" line with "s == 3". An error appears saying "s" cannot be resolved. public class S3 { public static void main(String[] args) { int s; for (int i = 0; i < 10; i++) { s = i; System.out.println("i " + i); } } }
's' is not resolved because the local variable doesn't exist yet (was no initialised). The local variable table indicate that the variable exists only for line 7 and the 'increment' part of the loop (line 5). The result of 'javap -l S3' is : Compiled from "S3.java" public class S3 extends java.lang.Object{ public S3(); LineNumberTable: line 1: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LS3; public static void main(java.lang.String[]); LineNumberTable: line 5: 0 line 6: 5 line 7: 7 line 5: 29 line 9: 38 LocalVariableTable: Start Length Slot Name Signature 0 39 0 args [Ljava/lang/String; 7 25 1 s I 2 36 2 i I } I get the result if I compile the class with javac. Moving to JDT/core (for comment, afaik, it's the right behavior).
grmfff... s/I get the result/I get the same result/
I don't see what we can do. 's' is only visible once the istore has been done. Before that the local has no value and therefore cannot appear in the local variable table attribute.
I guess this is just user error. However, the error message was misleading, since - i.e. "can't resolve 's'" just looks wrong when the variable is already declared. I'm going to move this back to debug, and mark as later. Perhaps we can provide a better error message in this case. But it's not critical.
Deferred
Nothing to fix.
Closing
As of now 'LATER' and 'REMIND' resolutions are no longer supported. Please reopen this bug if it is still valid for you.