You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "NicolaIsotta (via GitHub)" <gi...@apache.org> on 2023/07/04 08:43:43 UTC

[GitHub] [netbeans] NicolaIsotta opened a new issue, #6149: `Objects.requireNonNull` should disable "Null Pointer Dereference" warnings

NicolaIsotta opened a new issue, #6149:
URL: https://github.com/apache/netbeans/issues/6149

   ### Apache NetBeans version
   
   Apache NetBeans 18
   
   ### What happened
   
   Using `Objects.requireNonNull` should disable "Null Pointer Dereference" warnings. Instead, it doesn't.
   
   ### How to reproduce
   
   ```java
   public static String myToString(Object object) {
       Objects.requireNonNull(object);
       if (object instanceof Number) {
           DecimalFormat df = new DecimalFormat("#.00");
           return df.format(((Number) object).doubleValue());
       } else {
           return object.toString();
       }
   }
   ```
   
   ### Did this work correctly in an earlier version?
   
   No / Don't know
   
   ### Operating System
   
   Windows 10 version 10.0 running on amd64; Cp1252; it_IT (nb)
   
   ### JDK
   
   11.0.14.1; OpenJDK 64-Bit Server VM 11.0.14.1+1
   
   ### Apache NetBeans packaging
   
   Apache NetBeans binary zip
   
   ### Anything else
   
   ![null warning](https://github.com/apache/netbeans/assets/18428155/6470fe7e-e4e9-4306-96de-3b02be74788b)
   
   if `Objects.requireNonNull(object);` is replaced by `if (object == null) throw new NullPointerException();` the warning disappears.
   
   ### Are you willing to submit a pull request?
   
   No


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] asbachb commented on issue #6149: `Objects.requireNonNull` should disable "Null Pointer Dereference" warnings

Posted by "asbachb (via GitHub)" <gi...@apache.org>.
asbachb commented on issue #6149:
URL: https://github.com/apache/netbeans/issues/6149#issuecomment-1627484452

   Here's an additional test for `NPECheckTest` to prove the problem:
   
   ```java
       public void testObjectsRequireNonNull() throws Exception {
           HintTest.create()
                   .input("package test;\n"
                           + "import java.util.Objects;\n"
                           + "public class Test {\n"
                           + "  public String test(Object obj) {\n"
                           + "    Objects.requireNonNull(obj);\n"
                           + "    if (obj instanceof Number)\n"
                           + "      return \"\";\n"
                           + ""
                           + "    return obj.toString();\n"
                           + "  }\n"
                           + "}")
                   .run(NPECheck.class)
                   .assertNotContainsWarnings("7:15-7:23:verifier:Possibly Dereferencing null");
       }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] mbien closed issue #6149: `Objects.requireNonNull` should disable "Null Pointer Dereference" warnings

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien closed issue #6149: `Objects.requireNonNull` should disable "Null Pointer Dereference" warnings
URL: https://github.com/apache/netbeans/issues/6149


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists