Project: JDT
Bug 264421 [quick assist] convert to enhanced for loop applied incorrectly
Reported: 2009-02-10 16:23:02 | Status: verified fixed

Build ID: M20080911-1700 Steps To Reproduce: Perhaps this isn't the prettiest code in the world, but it was encountered in real code. I can happily point to a public svn repo to prove it :-). Anyway, this is the original code public class ForLoopTest { public static void main(String[] args) { String[] src = new String[] { "1", "2", "3", "4" }; for (int i = 0; i < src.length; i++) { String path = src[i]; String output = path; if (output.length() == 1) { output = output + "-XXX"; } System.err.println("path="+ path + ",output="+output); } } } After applying the logic to convert the for loop, this is the result: public class ForLoopTest { public static void main(String[] args) { String[] src = new String[] { "1", "2", "3", "4" }; for (String path : src) { if (path.length() == 1) { path = path + "-XXX"; } System.err.println("path="+ path + ",output="+path); } } } Running the two versions of the program produce different output :-( Output before: path=1,output=1-XXX path=2,output=2-XXX path=3,output=3-XXX path=4,output=4-XXX Output after: path=1-XXX,output=1-XXX path=2-XXX,output=2-XXX path=3-XXX,output=3-XXX path=4-XXX,output=4-XXX More information:

Files changed in fix:
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/ConvertForLoopOperation.java