Bug 91757

Summary: Enhanced for-loop behaves badly when optimizing
Product: [Eclipse Project] JDT Reporter: Olav Müller <olav.mueller>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Olav Müller CLA 2005-04-18 12:22:54 EDT
When I compile this code with jdk 1.5 and deactivating (!) the "preserve unused
(never read) local variables" in classfile options the generated classfile will
throw an Error as ilist.next() is never called:

public static void main( String[] args ) {
  List<String> ilist = new ArrayList<String>();
  ilist.add( "Dies" );
  ilist.add( "ist" );
  ilist.add( "ein" );
  ilist.add( "Test" );
  int count = 0;
  for( String o : ilist ) {
    count++;
    if( count > 10 ) {
      throw new Error();
    }
  }
}

I think this should at least give a warning.
Comment 1 Philipe Mulet CLA 2005-04-18 12:53:42 EDT
Which build are you using ?
Comment 2 Philipe Mulet CLA 2005-04-18 12:58:35 EDT
Smells like dup of bug 86487
Comment 3 Philipe Mulet CLA 2005-04-18 13:10:01 EDT

*** This bug has been marked as a duplicate of 86487 ***