@Override public void visitClassObjectAccessExpression(PsiClassObjectAccessExpression expression) {
startElement(expression);
- PsiElement[] children = expression.getChildren();
- for (PsiElement child : children) {
- child.accept(this);
- }
- pushUnknown();
+ addInstruction(new PushInstruction(myFactory.createTypeValue(expression.getType(), Nullness.NOT_NULL), expression));
finishElement(expression);
}
if (!(psi instanceof PsiField) || !psi.hasModifierProperty(PsiModifier.VOLATILE)) {
memState.setVarValue(var, dfaSource);
}
+ if (var.getInherentNullability() == Nullness.NULLABLE && !memState.isNotNull(dfaSource) && instruction.isVariableInitializer()) {
+ DfaMemoryStateImpl stateImpl = (DfaMemoryStateImpl)memState;
+ stateImpl.setVariableState(var, stateImpl.getVariableState(var).withNullability(Nullness.NULLABLE));
+ }
+
} else if (dfaDest instanceof DfaTypeValue && ((DfaTypeValue)dfaDest).isNotNull()) {
checkNotNullable(memState, dfaSource, NullabilityProblem.assigningToNotNull, instruction.getRExpression());
}
import com.intellij.codeInspection.dataFlow.InstructionVisitor;
import com.intellij.codeInspection.dataFlow.value.DfaValue;
import com.intellij.psi.PsiExpression;
+import com.intellij.psi.PsiVariable;
import org.jetbrains.annotations.Nullable;
public class AssignInstruction extends Instruction {
return visitor.visitAssign(this, runner, stateBefore);
}
+ @Nullable
public PsiExpression getRExpression() {
return myRExpression;
}
+ public boolean isVariableInitializer() {
+ return myRExpression != null && myRExpression.getParent() instanceof PsiVariable;
+ }
+
@Nullable
public DfaValue getAssignedValue() {
return myAssignedValue;
--- /dev/null
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+abstract class IDEATest {
+ abstract Object someMethod(@NotNull Object someParam);
+ abstract Object someObject();
+
+ public void testIDEA() {
+ @Nullable Object obj2 = someObject();
+ someMethod(<warning descr="Argument 'obj2' might be null">obj2</warning>);
+ }
+}
\ No newline at end of file
public void testNullCheckDoesntAffectUncheckedCast() { doTest(); }
public void testThrowNull() { doTest(); }
+ public void testExplicitlyNullableLocalVar() { doTest(); }
+
public void testTryWithResourcesNullability() { doTest(); }
public void testTryWithResourcesInstanceOf() { doTest(); }
public void testOmnipresentExceptions() { doTest(); }