Project: JDT
Bug 374264 [clean up] Convert for loop to enhanced applied to iterator produces broken code
Reported: 2012-03-14 12:03:26 | Status: resolved fixed

Build Identifier: 20120216-1857 public static void main(String[] args) { List<String> list = new ArrayList<String>(Arrays.asList("first", "second", "third")); for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) { removeSecond(iterator); } System.out.println(list); } private static void removeSecond(Iterator<String> iterator) { if ("second".equals(iterator.next())) { iterator.remove(); } } Reproducible: Always Steps to Reproduce: 1.Enter the code from details into any class 2.Check that "Convert for loop to enhanced" is checked in Save actions. 3.Save. Detected: "for (Iterator<String> iterator = list.iterator(); iterator.hasNext();)" string is changed to "for (String string : list)", the code becomes broken - compilation error. Expected: Code should not be changed. Workaround: not using "Convert for loop to enhanced" functionality.

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