Bug 190737 - [compiler][null] missing 'cannot be null' warning within for loop
Summary: [compiler][null] missing 'cannot be null' warning within for loop
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC All
: P5 normal (vote)
Target Milestone: 3.6 M4   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 212013 220788 291418 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-06-04 02:16 EDT by Maxime Daniel CLA
Modified: 2011-03-04 08:43 EST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Daniel CLA 2007-06-04 02:16:04 EDT
I20070531-0010
The following test case raises no error while it should:
public class X {
  void foo(Object o) {
    if (o != null) {
      for (int i = 0; i < Integer.MAX_VALUE; i++) {
        if (o == null) { // cannot be null
        }
      }
    }
  }
}
Comment 1 Maxime Daniel CLA 2007-06-04 02:17:02 EDT
Entered (inactive) test case NullReferenceTest#745.
Comment 2 Maxime Daniel CLA 2007-12-05 11:31:13 EST
*** Bug 212013 has been marked as a duplicate of this bug. ***
Comment 3 Markus Keller CLA 2009-03-13 09:49:55 EDT
A similar case but the other way 'round (missing "redundant null check"):

public class Try {
    public static void main(String[] args) {
        Number n= getNumber();
        if (n instanceof Double) {
            Double d= (Double) n;
            if (d != null && d.isNaN()) { //"redundant null check" (good)
                System.out.println("outside loop");
            }
            for (int i= 0; i < 10; i++) {
                if (d != null && d.isNaN()) { //"redundant null check" missing
                    System.out.println("inside loop");
                }
            }

        }
    }

    private static Number getNumber() {
        return new Double(Math.sqrt(-1));
    }
}
Comment 4 Olivier Thomann CLA 2009-11-19 09:10:18 EST
*** Bug 291418 has been marked as a duplicate of this bug. ***
Comment 5 Olivier Thomann CLA 2009-11-19 09:10:43 EST
Patch is provided in bug 291418.
Comment 6 Olivier Thomann CLA 2009-11-19 09:24:09 EST
Released for 3.6M4.
Added regression tests in:
org.eclipse.jdt.core.tests.compiler.regression.NullReferenceTest#testBug291418a
org.eclipse.jdt.core.tests.compiler.regression.NullReferenceTest#testBug291418b
Comment 7 Srikanth Sankaran CLA 2009-12-08 01:11:16 EST
Verified for 3.6M4 using Build id: I20091207-1800.
The inverse problem mentioned in comment#3 is still there,
Ayush, I believe this case is covered in the several
already existing defects ? If so, please add an annotation
here to that effect, otherwise, open a separate defect for
that -- Thanks.
Comment 8 Ayushman Jain CLA 2009-12-08 05:01:45 EST
(In reply to comment #3)
> A similar case but the other way 'round (missing "redundant null check"):
> 

This case is still not rectified with this bug. This, although not an exact duplicate, is a close relative of bug 129581 and bug 190623. All these cases pertain to sequel null errors, where a variable checked against null gets tainted and loses the surety of being non null subsequently. This problem should also be fixed along with these related bugs. This case has been added as comment #9 on bug 190623.
Comment 9 Markus Keller CLA 2009-12-08 05:43:20 EST
> This case has been added as comment #9 on bug 190623.

Thanks. BTW: To create a direct link, switch comment and bug #, e.g.:
Bug 190623 comment 9.
Comment 10 Olivier Thomann CLA 2011-03-04 08:43:13 EST
*** Bug 220788 has been marked as a duplicate of this bug. ***