Project: JDT
Bug 234984 [clean up] Code cleanup conversion to a for each loop makes the assigned variable final when it shouldn't
Reported: 2008-05-31 08:57:25 | Status: resolved fixed

My code cleanup export is attached. //---------------------------------------- //1. Using the following snippet as the original //---------------------------------------- public void method(String[] arr) { for (int i = 0; i < arr.length; i++) { String item = arr[i]; item = item + "a"; } } //---------------------------------------- //---------------------------------------- //2. Running a code clean up makes the variable final. //But it is changed inside the loop, so the code doesn't compile. //Compiler fails at line 5, nl. 'item = item + "a";'. //---------------------------------------- public void method(String[] arr) { for (final String item : arr) { item = item + "a"; } } //----------------------------------------

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/ConvertForLoopOperation.java org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/ConvertIterableLoopOperation.java