Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/MethodReferenceBoundToNullable.java
Tagir Valeev 395ea720e9 MethodReferenceBoundToNullable.java: added explanatory comment
GitOrigin-RevId: b84ec989638fea04df2dd10dac1a01638843543b
2020-01-21 04:38:18 +00:00

24 lines
1.1 KiB
Java

import java.util.Collections;
import java.util.List;
import java.util.function.Function;
// IDEA-186732
// In general nullability inference is unspecified and it's not clear whether `? super F` must be substituted via
// `@Nullable String`. Now it works because we propagate annotations through
// com.intellij.psi.impl.source.resolve.graphInference.constraints.TypeEqualityConstraint. However, normal Java
// type inference should ignore annotations completely, so we might drop the support of this case in the future
// or define nullability inference in more strict way.
class MethodRef {
public static <F, T> List<T> transform(
List<F> fromList, Function<? super F, ? extends T> function) {
return Collections.emptyList();
}
public static void useGuavaListsTransform_method_ref(List<@foo.Nullable String> list) {
System.out.println(transform(list, s -> s.<warning descr="Method invocation 'length' may produce 'NullPointerException'">length</warning>()));
System.out.println(transform(list, <warning descr="Method reference invocation 'String::length' may produce 'NullPointerException'">String::length</warning>));
}
}