Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It may be a limitation in FindBugs; I agree that you've covered all the bases, but your null-check is split across two different conditions. Now these conditions happen to be complementary, so at least one of them will fire if <code>a</code> is null, but depending how sophisticated FindBugs is, it may not recognise this.</p> <p>Two options here, then:</p> <ol> <li><p>Just ignore the FindBugs warning. Due to its nature it <em>will</em> raise some false positives from time to time, so don't feel like you have to rewrite your code to make it 100% happy if you don't think the rewrite is worthwhile on its own merits.</p> <p>You can use the <a href="http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/SuppressWarnings.html" rel="nofollow noreferrer"><code>@SuppressWarnings</code> annotation</a> to actually communicate this to FindBugs, if you want the report to show a nice big zero at the end. See <a href="https://stackoverflow.com/questions/1829904/is-there-a-way-to-ignore-a-single-findbugs-warning">this question</a> for an example.</p></li> <li><p>Restructure the condition so that the nullity check on <code>a</code> is more explicit, by nesting <code>if</code> blocks:</p> <pre><code>if (a == null) { return b == null ? 0 : -1; } return b == null ? 1 : a.compareTo(b); </code></pre> <p>Depending on your tastes and style that might be a better rewrite anyway, in that is more clearly says "if <code>a</code> is null, do <em>this</em> calculation and return it, otherwise do <em>this</em> calculation". You can of course change the ternary condition into another <code>if-else</code> block if you prefer that.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload