Community
Participate
Working Groups
The warning below shows up when it shouldn't, the first iteration of the code loop always executes. Similar cases can be constructed with if() statements. /** * @author oharboe */ public class Test { public int foo() { int t; for (int i=0; i<10; i++) { t=1*i; } // The local variable t may not have been initialized return t; } }
This is a consequence of the conservative definite assignment rules described in JLS (chapter 16). In brief, the analysis doesn't look deep enough to figure that it will perform at least one iteration in the loop (it could since only constants are involved, but this is the conservative spec we implement). Javac and Jikes behave in the same way.
Closing, following the JLS.