Files
openide/java/java-tests/testData/inspection/nullableProblems/OverriddenViaMethodReference.java
T
Tagir Valeevandintellij-monorepo-bot 69ba31aaf2 [java-inspections] Remove completely 'Not annotated method is used as an override...' on method ref target
As we can call method ref in certain context, it's not evident that only not-null methods should be accepted there. Methods like Map::get with unknown nullability can also be accepted (e.g. if we know that the target method never returns null for method reference parameter)

GitOrigin-RevId: 64460ffed311b6620133a4079293f7b20dec5f46
2022-04-26 16:34:33 +00:00

43 lines
1.1 KiB
Java

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
interface NonnullInterface {
@NotNull
Object nonNullMethod();
}
class P2 {
private void callTest() {
test(new NonnullInterface() {
<warning descr="Method annotated with @Nullable must not override @NotNull method">@Nullable</warning>
@Override
public String nonNullMethod() {
return null;
}
});
test(this::<warning descr="Method annotated with @Nullable must not override @NotNull method">getNull</warning>);
test(this::getPrimitive);
test(this::getNonAnnotated);
test(WithImplicitConstructor::new);
test(WithExplicitConstructor::new);
}
@Nullable
String getNull() { return null; }
String getNonAnnotated() { return null; }
boolean getPrimitive() { return true; }
private void test(final NonnullInterface function) { }
private Iterable<String> arrayToIterable(String... array) {
return Arrays.stream(array)::iterator;
}
}
class WithImplicitConstructor {}
class WithExplicitConstructor { WithExplicitConstructor() {} }