java:S2637 "@NonNull" values should not be set to null

System informations:

  • SonarQube Server: 2026.1.5.126862 ( Developer Edition )
  • How is SonarQube deployed: zip

I have the following behavior:

import java.util.Objects;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
class Foo {
  
  private final Bar bar;

  public Foo(@Nullable Bar bar) {
    // Sonar raises issue java:S2637 : "bar" is marked "@NullMarked at 
    // class level" but is set to null.
    this.bar = Objects.requireNonNullElseGet(bar, Bar::new);
  }

}

Objects.requireNonNullElseGet cannot return null even if the provided Supplier returns null.

Therefore, this looks like a bug.