mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
handleFlush: do not use inherent nullability for unknown values
Fixes IDEA-172844 False positive "Method invocation 'methodName' may produce NPE" in while loop condition
This commit is contained in:
+2
-1
@@ -269,7 +269,8 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
|
||||
private DfaValue handleFlush(DfaVariableValue flushed, DfaValue value) {
|
||||
if (value instanceof DfaVariableValue && (value == flushed || myFactory.getVarFactory().getAllQualifiedBy(flushed).contains(value))) {
|
||||
Nullness nullability = isNotNull(value) ? Nullness.NOT_NULL : ((DfaVariableValue)value).getInherentNullability();
|
||||
Nullness nullability = isNotNull(value) ? Nullness.NOT_NULL :
|
||||
isUnknownState(value) ? Nullness.UNKNOWN : ((DfaVariableValue)value).getInherentNullability();
|
||||
return myFactory.createTypeValue(((DfaVariableValue)value).getVariableType(), nullability);
|
||||
}
|
||||
return value;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
// IDEA-172844
|
||||
abstract class SimpleClass {
|
||||
|
||||
@Nullable
|
||||
protected MyType findSelfOrInnerByNonQualifiedName() {
|
||||
MyType nearestOuter = getOwnerParentOfType(MyType.class);
|
||||
if (nearestOuter != null) {
|
||||
MyType currentOuter = nearestOuter;
|
||||
while (currentOuter.getOuterClass() != null) { // False positive error here
|
||||
currentOuter = currentOuter.getOuterClass();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
abstract MyType getOwnerParentOfType(Class<MyType> apexPsiTypeDeclarationClass);
|
||||
|
||||
static abstract class MyType {
|
||||
|
||||
@Nullable
|
||||
abstract MyType getOuterClass();
|
||||
}
|
||||
}
|
||||
@@ -583,4 +583,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testLessThanRelations() { doTest(); }
|
||||
public void testAdvancedArrayAccess() { doTest(); }
|
||||
public void testNullabilityBasics() { doTest(); }
|
||||
public void testNullableGetterInLoop() { doTest(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user