Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Please take java.util.Objects methods into account for potential NullPointer checks
Please take java.util.Objects methods into account for potential NullPointer checks [message #1823227] Mon, 23 March 2020 05:23 Go to next message
Eclipse UserFriend
I find potential null pointer access warnings really useful. However, since Java (1.)7 there is a utility class java.util.Objects which offers a couple of checks such as
boolean isNull(<obj>) or
boolean nonNull<obj>)

If would be great, if the Java compiler's null-checks could take these standard methods into account and not flag snippets like
...
if (java.util.Objects.nonNull(account)) {
long id = account.getId();
... <doing something with account here> ...
}
...

as potential null-pointer access. Otherwise one tends to ignore or even disable these warnings and that would really be a pity.
Re: Please take java.util.Objects methods into account for potential NullPointer checks [message #1823236 is a reply to message #1823227] Mon, 23 March 2020 08:13 Go to previous messageGo to next message
Eclipse UserFriend
I already have plans to integrate knowledge about a few more well known utility methods into analysis (don't have the bug number off hand), but for the particular case of Objects.nonNull() your code snippet is abuse of the API, obscuring that you are doing nothing else but a traditional "account != null" check. Please read the javadoc of that method. It is not meant to be used this way.
Re: Please take java.util.Objects methods into account for potential NullPointer checks [message #1823561 is a reply to message #1823236] Sat, 28 March 2020 19:11 Go to previous message
Eclipse UserFriend
The case of Objects.isNull() or Objects.nonNull() didn't convince me, but we already had a similar request for Class.isInstance(), so I did implement the necessary analysis, and while I was at it, I included the two methods from java.util.Objects. Details are in https://bugs.eclipse.org/bugs/show_bug.cgi?id=465085

Next I may want to implement a warning when isNull() or nonNull() is explicitly called ;p
Previous Topic:Eclipse Not Responding Errors
Next Topic:error in running gradle based project with java9+ modules
Goto Forum:
  


Current Time: Mon Jul 14 23:20:17 EDT 2025

Powered by FUDForum. Page generated in 0.03603 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top