Note that there are some explanatory texts on larger screens.

plurals
  1. PO@Nullable input in Google Guava Function interface triggers FindBugs warning
    primarykey
    data
    text
    <p>The <code>com.google.common.base.Function</code> interface (from <a href="http://code.google.com/p/guava-libraries/wiki/Release13">Google Guava</a>) defines <code>apply</code> as:</p> <p><code>@Nullable T apply(@Nullable F input);</code> </p> <p>The method has the following javadoc note:</p> <p><code>@throws NullPointerException if {@code input} is null and this function does not accept null arguments</code>.</p> <p>FindBugs complains about my implementation of Function:</p> <pre><code>private static final class Example implements Function&lt;MyBean, String&gt; { @Override @Nullable public String apply(@Nullable MyBean input) { if (null == input) { throw new NullPointerException(); } return input.field; } } </code></pre> <p>with a <strong>high-priority</strong> warning:</p> <blockquote> <p>NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE, Priority: High</p> <p>input must be nonnull but is marked as nullable</p> <p>This parameter is always used in a way that requires it to be nonnull, but the parameter is explicitly annotated as being Nullable. Either the use of the parameter or the annotation is wrong.</p> </blockquote> <p>My function does not support <code>null</code> inputs and an exception is thrown if that is the case. If I understand correctly, FindBugs treats this as a requirement for non-null.</p> <p>To me it looks like a contradiction: input is @Nullable but method @throws NullPointerException when it is null. Am I missing something? </p> <p>The only way to get rid of the warning that I can see is manual suppression. (Guava code is out of my control, obviously).</p> <p>Who is wrong about the usage of @Nullable annotation, FindBugs, Guava or myself?</p>
    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.
 

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