Community
Participate
Working Groups
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); } }
Move to JDT/UI
Cleanup belongs to UI. Alternatively, cleanup could inline increment expressions at the end of the for action block. But I agree that doing nothing is probably as good.
Created attachment 51743 [details] fix Clean Up does not convert the loop. On Quick Assist a warning is shown informing that the update expressions will be removed.
fixed > I20061010-0800
Verified in I20061030-1704.