Null analysis seems to ignore short-circuiting [message #1833427] |
Mon, 12 October 2020 18:18  |
Eclipse User |
|
|
|
I've been experimenting with null annotations.
I'm looking at the following block of code, which I did not write, and I've simplified it:
if (null != response.getCart().getStatus()
&& response.getCart().getStatus() .equalsIgnoreCase("SUCCESS")) {
Without any null annotations, no warnings appear here.
If I go to the "Cart" class and add "@NonNullByDefault" to the class, that results in the following warning on the first line of that block:
Quote:Redundant null check: comparing '@NonNull String' against null
This is expected, as it now believes that all the properties of that are not null, so I shouldn't compare it against null.
However, that particular property actually can be null, so I added @Nullable to the return type of the getter. This now results in the following warning on the SECOND line:
Quote:Potential null pointer access: The method getStatus() may return null
This is certainly true, but in this block of code, it's not possible to reach this line, as the first condition in the ANDed expression will be false, so it will never execute the second subexpression.
Is it reasonable for it to check for short-circuiting here and NOT emit this warning?
|
|
|
|
|
Re: Null analysis seems to ignore short-circuiting [message #1833436 is a reply to message #1833431] |
Tue, 13 October 2020 02:55  |
Eclipse User |
|
|
|
Hi
I have been using null annotations for over five years and find them very useful, but also very inadequate since the lack of PDE support means that each project can be a distinct non-null-island. Now that I know that PDE will almost certainly never fix up external annotations, I am endeavouring to use the analysis without external annotations and find that it is very irritating to have to add a lot of assert != null / maybeNull() fixes for analysis defeating methods such as Map.get. On balance, i think that the fixes to accommodate awkward methods, missing EMF support, bad quick fixes/refactorings are a price worth paying, but only just.
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.24834 seconds