mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-psi] IDEA-379789 Guava. Possible NPE is not highlighted
Correct nullability when inferring type variable from eq and lower bounds GitOrigin-RevId: 3c41bda2c36fd24568710ef2c9ca8b5ba0c70414
This commit is contained in:
committed by
intellij-monorepo-bot
parent
af71753a9a
commit
b44761dc38
+3
@@ -1192,6 +1192,9 @@ public class InferenceSession {
|
||||
return PsiTypes.nullType();
|
||||
} else {
|
||||
type = eqBound;
|
||||
if (!lowerBound.equals(PsiTypes.nullType())) {
|
||||
type = type.withNullability(eqBound.getNullability().join(lowerBound.getNullability()));
|
||||
}
|
||||
|
||||
if (isLowerBoundNotAssignable(var, eqBound, false)) {
|
||||
setErased();
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.NotNullByDefault;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class MyTest {
|
||||
@NotNullByDefault
|
||||
static class Iterables {
|
||||
public static native <T extends @Nullable Object> Iterable<T> concat(Iterable<? extends T> a, Iterable<? extends T> b);
|
||||
|
||||
public static native <T extends @Nullable Object> T[] toArray(
|
||||
Iterable<? extends T> iterable, Class<@NotNull T> type);
|
||||
|
||||
public static native <T extends @Nullable Object> T get(
|
||||
Iterable<T> iterable, int position);
|
||||
}
|
||||
|
||||
|
||||
void toArray(List<@Nullable String> l1) {
|
||||
for (String s : Iterables.toArray(l1, String.class)) {
|
||||
System.out.println(s.<warning descr="Method invocation 'length' may produce 'NullPointerException'">length</warning>());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void get(List<@Nullable String> l1) {
|
||||
System.out.println(Iterables.get(l1, 0).<warning descr="Method invocation 'length' may produce 'NullPointerException'">length</warning>());
|
||||
|
||||
}
|
||||
|
||||
void foo(List<String> l1, List<String> l2) {
|
||||
for (String s : Iterables.concat(l1, l2)) {
|
||||
System.out.println(s.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
import org.jetbrains.annotations.NotNullByDefault;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class MyTest {
|
||||
@NotNullByDefault
|
||||
static class Iterables {
|
||||
public static native <T extends @Nullable Object> Iterable<T> concat(Iterable<? extends T> a, Iterable<? extends T> b);
|
||||
}
|
||||
|
||||
void foo(List<String> l1, List<String> l2) {
|
||||
for (String s : Iterables.concat(l1, l2)) {
|
||||
System.out.println(s.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -212,7 +212,7 @@ public class DataFlowInspection21Test extends DataFlowInspectionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInheritNullableInstantiateUnknown() {
|
||||
public void testGuavaIterablesProblems() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user