This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 269324

Summary: "Dereferencing possible null pointer" after doing instanceof on variable (false positive)
Product: java Reporter: ebakke
Component: HintsAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 8.2   
Hardware: PC   
OS: Mac OS X   
Issue Type: DEFECT Exception Reporter:

Description ebakke 2016-12-13 19:28:10 UTC
In the following example, the "boolean foo = k instanceof Integer" assignment causes a spurious "Dereferencing possible null pointer" warning to occur on the "k.doubleValue()" expression. This is a bit annoying, and was not the case before. Note that if the assignment to "boolean foo" is replaced by an if statement ("if (k instanceof Integer)"), the warning goes away.

=======================================================
public class TestClass {
  private Number getFoo() {
    return 3;
  }

  public void testFoo() {
    Number k = getFoo();
    // The warning only occurs if this assignment is present.
    boolean foo = k instanceof Integer;
    // Warning on .doubleValue() here: "Dereferencing possible null pointer"
    System.out.println(k.doubleValue());
  }
}
=======================================================
Comment 1 ebakke 2018-02-18 03:52:50 UTC
This bug moved to the new Apache JIRA at https://issues.apache.org/jira/browse/NETBEANS-406 .
Comment 2 ebakke 2018-02-18 03:54:50 UTC
Correction: The new JIRA issue for this bug is https://issues.apache.org/jira/browse/NETBEANS-407 .