Community
Participate
Working Groups
Look at the following code: Report bug to eclipse. This code is "unreachable" but it's always showing the wrong section: public static long test2() { long sum = 0; for (int i = 0; 1 < 1000; i++) { sum += i; } return sum; } Turns out there's a bug in the code: It shouldn't be "1 < 1000", it should be "i < 1000". However, that creates an "unreachable code" error, since the "sum += i" line can't be reached. Where does Eclipse choose to mark the error? At the line "return sum". Thanks, Rob
The error location isn't what I would have guessed either, but neither javac 1.5.0 or jikes do any better than we do on this one. D:\src>javac X.java -d ..\bin -Xlint X.java:7: unreachable statement return sum; ^ 1 error D:\src>jikes X.java -d ..\bin -cp d:\jdk1.4.2\jre\lib\rt.jar Found 1 semantic error compiling "D:/src/X.java": 7. return sum; ^---------^ *** Semantic Error: This statement is unreachable.
Actually, we do the right thing. 1 < 1000 is equivalent to true, so the code inside the loop is definitely reachable, but since the loop has no exit point, then the next statement ("return sum;") is made unreachable. Had you written 1 > 1000 instead, you'd see the statement inside the loop being flagged as unreachable. Closing as invalid