Project: JDT
Bug 160270 [clean up] Converting iterable loop removes update expressions
Reported: 2006-10-10 03:23:27 | Status: verified fixed

We tested a general cleanup of our code and found a problem with the cleanup of loops. The following testcase shows that cleanup removes code in the for-loop that it shouldn't, the "i++" is silently removed although later code depends on it. I think in these cases the cleanup should just do nothing to avoid changing behaviour: public void testEclipseLoopCleanupError() { // //////////////////////////////////////////////// // before cleanup // //////////////////////////////////////////////// { List<String> output = new LinkedList<String>(); output.add("Test1"); int i = 0; for (Iterator<String> it = output.iterator(); it.hasNext(); ++i) { final String o = it.next(); assertEquals("Test1", o); } assertEquals(1, i); } // //////////////////////////////////////////////// // after cleanup // //////////////////////////////////////////////// { List<String> output = new LinkedList<String>(); output.add("Test1"); int i = 0; for (String o : output) { assertEquals("Test1", o); } assertEquals(1, i); } }

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/ConvertIterableLoopOperation.java org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.java