mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
IDEA-228079 Bad code green when dereferencing an unannotated parameter with nullable super
GitOrigin-RevId: ff3b4f3c7c01c2fb5aa90107037517653cadafa2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
680f4703db
commit
3a7ab57eb2
@@ -128,10 +128,13 @@ public class DfaPsiUtil {
|
||||
private static Nullability getNullabilityFromAnnotation(PsiModifierListOwner owner, boolean ignoreParameterNullabilityInference) {
|
||||
NullableNotNullManager manager = NullableNotNullManager.getInstance(owner.getProject());
|
||||
NullabilityAnnotationInfo info = manager.findEffectiveNullabilityInfo(owner);
|
||||
if (info == null ||
|
||||
ignoreParameterNullabilityInference && owner instanceof PsiParameter && AnnotationUtil.isInferredAnnotation(info.getAnnotation())) {
|
||||
if (info == null) {
|
||||
return Nullability.UNKNOWN;
|
||||
}
|
||||
if (ignoreParameterNullabilityInference && owner instanceof PsiParameter && AnnotationUtil.isInferredAnnotation(info.getAnnotation())) {
|
||||
List<PsiParameter> supers = AnnotationUtil.getSuperAnnotationOwners((PsiParameter)owner);
|
||||
return ContainerUtil.exists(supers, each -> manager.isNullable(each, false)) ? Nullability.NULLABLE : Nullability.UNKNOWN;
|
||||
}
|
||||
return info.getNullability();
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public interface VariableDescriptor {
|
||||
}
|
||||
PsiType type = getType(null);
|
||||
LongRangeSet range = LongRangeSet.fromPsiElement(getPsiElement());
|
||||
DfType dfType = DfTypes.typedObject(type, DfaPsiUtil.getElementNullability(type, getPsiElement()));
|
||||
DfType dfType = DfTypes.typedObject(type, DfaPsiUtil.getElementNullabilityIgnoringParameterInference(type, getPsiElement()));
|
||||
if (dfType instanceof DfIntegralType) {
|
||||
dfType = ((DfIntegralType)dfType).meetRange(range);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
interface Foo {
|
||||
void test(@Nullable String s);
|
||||
}
|
||||
|
||||
class Bar implements Foo {
|
||||
@Override
|
||||
public void test(String s) {
|
||||
System.out.println(s.<warning descr="Method invocation 'trim' may produce 'NullPointerException'">trim</warning>());
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testLocalClass() { doTest(); }
|
||||
|
||||
public void testNotNullOnSuperParameter() { doTest(); }
|
||||
public void testNullableOnSuperParameter() { doTest(); }
|
||||
|
||||
public void testFieldInAnonymous() { doTest(); }
|
||||
public void testFieldInitializerInAnonymous() { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user