Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8523293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:22:06+00:00 2026-06-11T07:22:06+00:00

The com.google.common.base.Function interface (from Google Guava ) defines apply as: @Nullable T apply(@Nullable F

  • 0

The com.google.common.base.Function interface (from Google Guava) defines apply as:

@Nullable T apply(@Nullable F input);

The method has the following javadoc note:

@throws NullPointerException if {@code input} is null and this function does not accept null arguments.

FindBugs complains about my implementation of Function:

private static final class Example implements Function<MyBean, String> {
    @Override
    @Nullable
    public String apply(@Nullable MyBean input) {
        if (null == input) {
            throw new NullPointerException();
        }
        return input.field;
    }
}

with a high-priority warning:

NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE, Priority: High

input must be nonnull but is marked as nullable

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.

My function does not support null inputs and an exception is thrown if that is the case. If I understand correctly, FindBugs treats this as a requirement for non-null.

To me it looks like a contradiction: input is @Nullable but method @throws NullPointerException when it is null. Am I missing something?

The only way to get rid of the warning that I can see is manual suppression. (Guava code is out of my control, obviously).

Who is wrong about the usage of @Nullable annotation, FindBugs, Guava or myself?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:22:08+00:00Added an answer on June 11, 2026 at 7:22 am

    Your implementation is wrong 😉

    Basically docs says (I’ll paraphrase and emphasise):

    @throws NullPointerException if input is null and the concrete
    function implementation
    does not accept null arguments

    By implementing your function you must decide if it accepts nulls or not. In first case:

    private static final class Example implements Function<MyBean, String> {
        @Override
        @Nullable
        public String apply(@Nullable MyBean input) {
            return input == null ? null : input.field;
        }
    }
    

    In second case:

    private static final class Example implements Function<MyBean, String> {
        @Override
        @Nullable
        public String apply(MyBean input) {
            if (null == input) {
                throw new NullPointerException();
            }
            return input.field;
        }
    }
    

    In both examples returning null is allowed.

    EDIT:

    Note that Guava uses @javax.annotation.ParametersAreNonnullByDefault on all packages, hence if @Nullable is present it means “suspend global @Nonnull and allow nulls here” and if not it means “nulls forbidden here”.

    That said, you may want use @Nonnull annotation on your argument or @ParametersAreNonnullByDefault in package to tell FindBugs Function’s argument can’t be null.

    EDIT 2:

    Turns out this case is known issue, see comment #3 (from Guava’s lead dev Kevin Bourrillion, about his conversation with Bill Pugh, Findbugs’ lead):

    My reference was a series of in-person conversations with Bill Pugh.
    He asserted unambiguously that @Nullable means only that some subtypes
    might 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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the interface Predicate<T> from com.google.common.base (Google Guava) But I don't know how
I was using com.google.common.collect.PrimitiveArrays from Google Collections, however I cannot find it in Guava,
In my Java code, I am using Guava's Multimap ( com.google.common.collect.Multimap ) by using
In my Java code, I am using Guava's Multimap ( com.google.common.collect.Multimap ) by using
I get the following error: Exception in thread main java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet; at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399) at
since version 10 guava offers com.google.common.eventbus.EventBus - a generic pub-sub facility. It is not
GAE not works with: import com.google.appengine.repackaged.com.google.common.base.Hash; import com.google.appengine.repackaged.com.google.common.io.ByteStreams; and my code: byte[] inputBytes; try
I currently face the problem of java.lang.NoClassDefFoundError: com.google.common.collect.HashBiMap when using guava libraries downloaded from
I need to remove element from com.google.gwt.core.client.JsArray . Also I need to empty the
In my GWT app I have the following model class: import com.google.gwt.user.client.rpc.IsSerializable; public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.