FP on squid:S4449 for nullable Guava method parameters

Hi all!

I think I may have found a false positive. On SonarCloud, S4449 raises an issue for the following code:

String foo = map.get(key);
return Optional.fromNullable(foo); // FP

Annotate the parameter with @javax.annotation.Nullable in method ‘fromNullable’ declaration, or make sure that null can not be passed as argument.

However, this seems to be already the case:

  • com.google.common.base is annotated with javax.annotation.ParametersAreNonnullByDefault
  • The parameter of Optional.fromNullable() is annotated with org.checkerframework.checker.nullness.qual.Nullable

I’m not sure whether these two annotations from two different packages are supposed to be mixed, though. Is this an error in SonarJava or in Guava?

The exact same situation exists with com.google.common.util.concurrent.SettableFuture. Here are the SonarCloud issues in our project for both Optional and SettableFuture.

We use Guava version 25.1-jre, but the relevant code is unchanged in 26.0.

Best regards,
Jens

Never mind, I just discovered SONARJAVA-2776 which seems to be in progress. Thanks!

1 Like