Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-407

"Dereferencing possible null pointer" after doing instanceof on variable (false positive)

    XMLWordPrintableJSON

Details

    Description

      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. I believe this did not happen in earlier NetBeans versions (pre-8.2). 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());
        }
      }
      

      This bug was previously described at https://netbeans.org/bugzilla/show_bug.cgi?id=269324 .

      Attachments

        Issue Links

          Activity

            People

              jlahoda Jan Lahoda
              ebakke Eirik Bakke
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m