mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-85035 Wrong "possible NPE" warning
This commit is contained in:
@@ -595,16 +595,6 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
}
|
||||
|
||||
if (dfaRight instanceof DfaNotNullValue) {
|
||||
if (dfaLeft instanceof DfaVariableValue) {
|
||||
DfaVariableState varState = getVariableState((DfaVariableValue)dfaLeft);
|
||||
DfaVariableValue dfaVar = (DfaVariableValue)dfaLeft;
|
||||
DfaTypeValue type = myFactory.getTypeFactory().create(((DfaNotNullValue)dfaRight).getType());
|
||||
if (isNegated) {
|
||||
return applyCondition(myFactory.getRelationFactory().create(dfaVar, DfaUnknownValue.getInstance(), JavaTokenType.EQEQ, false));
|
||||
}
|
||||
return applyCondition(compareToNull(dfaVar, false)) && varState.setInstanceofValue(type);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class Bar3 {
|
||||
|
||||
@NotNull
|
||||
Object getObj() {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
void foo(Collection<Object> collection) {
|
||||
if (!collection.isEmpty()) {
|
||||
Object first = collection.iterator().next();
|
||||
if (first != getObj() || collection.size() > 0) {
|
||||
System.out.println(first.hashCode());
|
||||
}
|
||||
if (first == getObj() || collection.size() > 0) {
|
||||
System.out.println(first.hashCode());
|
||||
}
|
||||
if (first == null) {
|
||||
System.out.println(<warning descr="Method invocation 'first.hashCode()' may produce 'java.lang.NullPointerException'">first.hashCode()</warning>);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,5 +61,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
|
||||
public void testGeneratedEquals() throws Throwable { doTest(); }
|
||||
|
||||
public void testIDEA84489() throws Throwable { doTest(); }
|
||||
public void testComparingToNotNullShouldNotAffectNullity() throws Throwable { doTest(); }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user