False positive on Objects.requireNonNullElse

You code snippet analyzes fine for me. Here is a new reproduction case which demonstrates what we’re seeing here: GitHub - starkos/sonarlint-example: Example project for a SonarLint support request.

On line 13 of CliMain.java, the warning is "Parameter 1 to this constructor is marked "@NonNull" but null could be passed.sonarlint(java:S2637)". However, it is not possible for jobId to be null at that point in the code, since Objects.requireNonNullElse() can never return null.

1 Like