Bug 160270 - [clean up] Converting iterable loop removes update expressions
Summary: [clean up] Converting iterable loop removes update expressions
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.3 M3   Edit
Assignee: Benno Baumgartner CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-10 03:23 EDT by Dominik Stadler CLA
Modified: 2006-10-31 07:47 EST (History)
1 user (show)

See Also:


Attachments
fix (8.64 KB, patch)
2006-10-11 05:32 EDT, Benno Baumgartner CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dominik Stadler CLA 2006-10-10 03:23:27 EDT
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);
        }
    }
Comment 1 Frederic Fusier CLA 2006-10-10 03:38:04 EDT
Move to JDT/UI
Comment 2 Philipe Mulet CLA 2006-10-10 03:40:22 EDT
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.
Comment 3 Benno Baumgartner CLA 2006-10-11 05:32:42 EDT
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.
Comment 4 Benno Baumgartner CLA 2006-10-11 05:36:44 EDT
fixed > I20061010-0800
Comment 5 Dani Megert CLA 2006-10-31 07:47:24 EST
Verified in I20061030-1704.