Bug 86487 - [1.5] infinite loop in enhanced for statement when the current element is optimized out
Summary: [1.5] infinite loop in enhanced for statement when the current element is opt...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 91757 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-02-24 11:01 EST by Olivier Thomann CLA
Modified: 2005-04-18 13:10 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2005-02-24 11:01:51 EST
This code is an infinite loop when the code is compiled with unused locals
optimized out.

import java.util.ArrayList;

public class X {

    public static void main(String args[]) {
        ArrayList<Integer> arr = new ArrayList<Integer>();
        arr.add(0);
        arr.add(1);

		int counter = 0;
        // tested statement:
        for (int i : arr){
            ++counter;
        }
        System.out.println(counter + " elements found in the array list");
    }
}
Comment 1 Philipe Mulet CLA 2005-02-24 11:14:24 EST
Problem comes from unused local optimization. We forgot to still perform
iterator.next() invocation, thus looping forever.

Released fix.
Comment 2 Olivier Thomann CLA 2005-02-24 11:20:30 EST
Change milestone
Comment 3 Olivier Thomann CLA 2005-02-24 12:07:38 EST
Regression tests added in ForeachStatementTest.test029, test030 and test031.
Comment 4 David Audel CLA 2005-03-31 09:34:18 EST
Verified in I20050330-0500
Comment 5 Philipe Mulet CLA 2005-04-18 13:10:02 EDT
*** Bug 91757 has been marked as a duplicate of this bug. ***