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

Hint about dereferencing null pointer is wrong

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 12.0, 11.2, 11.3, 12.2
    • None
    • OpenJDK 11.0.2
      Gradle 6.4.1

    Description

      public static void main(String[] args)

      { Optional.ofNullable(getValue())//as instance of java.util.Optional .map((o)->o instanceof String ? ((String)o).substring(0) : o.toString()); }

      private static Object getValue()

      { return ""; }

      o.toString() show hint about dereferencing possible null pointer, but this is not possible in that case as check is ensured by optional. In example is used "String" for simplification, but in more abstract case you want to get value one way if it is instance of anything and other way from "o" if it is not instance of that type.

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            nb-user-2019 Netbeans User 2019
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: