Project: JDT
Bug 214340 [clean up] Bad enhanced for-loop for arrays which are fields
Reported: 2008-01-04 06:51:29 | Status: verified fixed

Build ID: M20071023-1652 Steps To Reproduce: 1. Create new class Foo as: class Foo { int[] array = new int[3]; boolean same(Foo that) { for ( int i = 0; i < array.length; i++ ) { if ( this.array[i] != that.array[i] ) return false; } return true; } static boolean same(Foo one, Foo two) { for ( int i = 0; i < one.array.length; i++ ) { if ( one.array[i] != two.array[i] ) return false; } return true; } } 2. Applying Clean Up action "Convert for loops to enhanced" produces the following code: class Foo { int[] array = new int[3]; boolean same(Foo that) { for ( int element : array ) { if ( element != element ) return false; } return true; } static boolean same(Foo one, Foo two) { for ( int element : one.array ) { if ( element != element ) return false; } return true; } } 3. This is clearly wrong as the comparison between different objects turns into self-comparison. More information:

Files changed in fix:
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ConvertForLoopQuickFixTest.java org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/ConvertForLoopOperation.java