Bug 86487

Summary: [1.5] infinite loop in enhanced for statement when the current element is optimized out
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: olav.mueller
Version: 3.1   
Target Milestone: 3.1 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:

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. ***