Bug 178895

Summary: [compiler][null] A for-each loop changes its value on each iterator but the null pointer analysis is not taking that into consideration
Product: [Eclipse Project] JDT Reporter: Ed Merks <Ed.Merks>
Component: CoreAssignee: Maxime Daniel <maxime_daniel>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.3   
Target Milestone: 3.3 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Fix + test case none

Description Ed Merks CLA 2007-03-22 16:54:55 EDT
This is a follow up to https://bugs.eclipse.org/bugs/show_bug.cgi?id=176283.

Simplified test case:
  void foo(List<Object> l, boolean b) {
        for (Object o: l) {
          if (b) {
                if (o != null) {
                  return;
                }
          } else {
                System.out.println(o.toString()); // warning here
          }
        }
  }

Contrast with:
  void bar(List<Object> l, boolean b) {
        Iterator<Object> i = l.iterator();
        Object o;
        while (i.hasNext()) {
          o = i.next();
          if (b) {
                if (o != null) {
                  return;
                }
          } else {
                System.out.println(o.toString()); // silent
          }
        }
  }
Comment 1 Maxime Daniel CLA 2007-03-23 04:33:01 EDT
Created attachment 61788 [details]
Fix + test case

ForeachStatement#analyseCode now marks the index of the loop as definitely unknown.
Comment 2 Maxime Daniel CLA 2007-03-27 04:58:53 EDT
Released for 3.3M7.
Comment 3 Olivier Thomann CLA 2007-04-27 10:28:09 EDT
Verified for 3.3M7 using I20070427-0010