Bug 91757 - Enhanced for-loop behaves badly when optimizing
Summary: Enhanced for-loop behaves badly when optimizing
Status: RESOLVED DUPLICATE of bug 86487
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M7   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-18 12:22 EDT by Olav Müller CLA
Modified: 2005-04-18 13:10 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***