Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/RequireNonNullMethodRef.java
Tagir Valeev 7dc1ba3f05 [java-dfa] Do not report nullable-to-unannotated for method references to library classes
The same was done for normal calls but not for method references
Fixes IDEA-287197 "Constant conditions & exceptions": The "Suggest @Nullable annotation..." option no longer supports Objects::requireNonNull method references.

GitOrigin-RevId: 42bf265d8ea1ce2a1ae1be519e2237e862e05492
2022-02-08 07:52:20 +00:00

30 lines
804 B
Java

import org.jetbrains.annotations.Nullable;
import java.util.Objects;
import java.util.stream.Stream;
class Main {
public static void main(String[] args) {
Stream.of("test1")
.map(Main::testNullableStaticMethod)
.map(Objects::requireNonNull);
Stream.of("test2")
.map(Main::testNullableStaticMethod)
.map(obj -> Objects.requireNonNull(obj));
Stream.of("test3")
.map(Main::testNullableStaticMethod)
.map(<warning descr="Method reference argument might be null but passed to non-annotated parameter">Main::requireNonNull</warning>);
}
static <T> T requireNonNull(T obj) {
if (obj == null) {
throw new NullPointerException();
}
return obj;
}
@Nullable
public static native String testNullableStaticMethod(String something);
}