Bug 212283 - [compiler][null] false positive on "redundant null check" involving loops and breaks
Summary: [compiler][null] false positive on "redundant null check" involving loops and...
Status: VERIFIED DUPLICATE of bug 184298
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.4 M2   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-07 12:09 EST by Tim Van Holder CLA
Modified: 2007-12-10 07:59 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Van Holder CLA 2007-12-07 12:09:25 EST
Build ID: M20071023-1652

Steps To Reproduce:

import java.util.Random;

public class Bug {

  public static class Dummy { // Only here so I have something to call
    public static int foo() { return new Random().nextInt(); }
    public static int bar() { return new Random().nextInt(); }
    public static int baz() { return new Random().nextInt(); }
  }

  public void bug() {
    RuntimeException e = null;
    while (e != null || Dummy.foo() > 0) {
      if (e != null || Dummy.bar() > 0)
        break; // always breaks out of the loop if e non-null
      if (Dummy.baz() > 0)
        e = new RuntimeException();
    }
    if (e != null)
      throw e;
  }

}

The last if incorrectly states that e is always null.

More information:

This also happens if the test for the break is

      if ( Dummy.bar() > 0)
        break;

but not if it is

      if (e != null)
        break;

So it seems like it is not considering ALL breaks as reasons for a loop condition being true after the loop.
Comment 1 Maxime Daniel CLA 2007-12-10 05:00:18 EST
Could reproduce it with M20070905-1045, but not with I20071204-1547.
Must be a dupe of bug 184298.
Comment 2 Maxime Daniel CLA 2007-12-10 05:21:08 EST
Released NullReferenceTest#467-469 (thanks for the test cases).
(Fredéric, as discussed, I'll rely on you for the verification - thx.)

*** This bug has been marked as a duplicate of bug 184298 ***
Comment 3 Frederic Fusier CLA 2007-12-10 07:59:59 EST
Verified using I20070921-0919 (aka 3.4M2)