Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your implementation is wrong ;)</p> <p>Basically docs says (I'll paraphrase and emphasise):</p> <blockquote> <p><code>@throws NullPointerException</code> if <code>input</code> is null and <strong>the concrete function implementation</strong> does not accept null arguments</p> </blockquote> <p>By implementing your function you must decide if it accepts nulls or not. In first case:</p> <pre><code>private static final class Example implements Function&lt;MyBean, String&gt; { @Override @Nullable public String apply(@Nullable MyBean input) { return input == null ? null : input.field; } } </code></pre> <p>In second case:</p> <pre><code>private static final class Example implements Function&lt;MyBean, String&gt; { @Override @Nullable public String apply(MyBean input) { if (null == input) { throw new NullPointerException(); } return input.field; } } </code></pre> <p>In both examples returning null is allowed.</p> <p><strong>EDIT:</strong></p> <p>Note that Guava uses <code>@javax.annotation.ParametersAreNonnullByDefault</code> on all packages, hence if <code>@Nullable</code> is present it means "suspend global <code>@Nonnull</code> and allow nulls here" and if not it means "nulls forbidden here". </p> <p>That said, you may want use <code>@Nonnull</code> annotation on your argument or <code>@ParametersAreNonnullByDefault</code> in package to tell FindBugs Function's argument can't be null.</p> <p><strong>EDIT 2:</strong></p> <p>Turns out <a href="http://code.google.com/p/guava-libraries/issues/detail?id=920" rel="noreferrer">this case is known issue</a>, see comment #3 (from Guava's lead dev Kevin Bourrillion, about his conversation with Bill Pugh, Findbugs' lead):</p> <blockquote> <p>My reference was a series of in-person conversations with Bill Pugh. He asserted unambiguously that <code>@Nullable</code> means only that some subtypes <em>might</em> accept null. And this seems to be borne out by findbugs for us -- our code passes the nullability checks pretty cleanly (though we should check again since this particular Function change was made).</p> </blockquote>
 

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