Bug 178895 - [compiler][null] A for-each loop changes its value on each iterator but the null pointer analysis is not taking that into consideration
Summary: [compiler][null] A for-each loop changes its value on each iterator but the n...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-22 16:54 EDT by Ed Merks CLA
Modified: 2007-04-27 10:28 EDT (History)
0 users

See Also:


Attachments
Fix + test case (2.35 KB, patch)
2007-03-23 04:33 EDT, Maxime Daniel CLA
no flags Details | Diff

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