Files
openide/java/java-tests/testData/inspection/nullableProblems/IncompatibleInstantiation.java
Bart van Helvertandintellij-monorepo-bot 94d5fdf882 [java] Replace not-null with non-null
To make error messages consistent #IDEA-374747 Fixed


(cherry picked from commit 328c5b355fcf56a7d1c165aab32220d37bdfcbc1)

IJ-MR-170004

GitOrigin-RevId: f00fb74ddbff84b18839c60648d664774d566966
2025-07-22 21:25:49 +00:00

39 lines
1.2 KiB
Java

import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.lang.annotation.ElementType;
import java.util.function.Supplier;
@NullMarked
class Main {
public static void main(String[] args) {
Main.<<warning descr="Non-null type parameter 'T' cannot be instantiated with @Nullable type">@Nullable</warning> Object>fNonNullBound(() -> getNullableObject());
Main.<<warning descr="Non-null type parameter 'T' cannot be instantiated with @Nullable type">@Nullable</warning> Object>fNonNullBound(Main::getNullableObject);
}
static <T extends @Nullable Object> T fNullableBound(Supplier<T> supplier){
return supplier.get();
}
static <T> T fNonNullBound(Supplier<T> supplier){
return supplier.get();
}
static @Nullable Object getNullableObject() {
return null;
}
@NullableScope
static class NullableScopeClass {
void test() {
Main.<<warning descr="Non-null type parameter 'T' cannot be instantiated under @NullableScope">Object</warning>>fNonNullBound(Main::getNullableObject);
}
}
}
@javax.annotation.meta.TypeQualifierDefault(ElementType.TYPE_USE)
@javax.annotation.Nullable
@java.lang.annotation.Target(ElementType.TYPE_USE)
@interface NullableScope {}