FP java:S4449 reports issue for null parameters for Guava Multimap#put

  • SonarQube Community Build v25.10.0.114319
  • Java Code
  • Rule java:S4449 Nullness of parameters should be guaranteed

This post is similar to FP java:S4449 reports issue for null parameter for Guava Iterables.getLast but for a different Guava method.

S4449 reports issues for both calls to Multimap#put in the following Java code:

package org.example;
import com.google.common.collect.Multimap;

public class S4449GuavaMultimap {
  void test(Multimap<Object, Object> multimap) {
    multimap.put(null, "value");
    multimap.put("key", null);
  }
}

The rule complains about both null keys and values here. But Guava Multimap allows null values. (Guava version 33.5.0-jre)

The signature of the called Guava method is using org.jspecify.annotations.Nullable

public interface Multimap<K extends @Nullable Object, V extends @Nullable Object> {
  ...

  @CanIgnoreReturnValue
  boolean put(@ParametricNullness K key, @ParametricNullness V value);

Because K and V are declared as extends @Nullable, it should be possible to use null keys and values.

The calling code isn’t using any Nullable annotations.

I’ve attached the above source as minimal maven project.

test.zip (1.8 KB)

Cheers
Andreas