mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-dfa] IDEA-332978 Nullability warning is not displayed in instanceof with pattern operand
GitOrigin-RevId: e0ea0bb2fae6eb9119310c8f7be56a05298733f8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2586b12f70
commit
d79850455f
+4
-13
@@ -1864,7 +1864,6 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
PsiType operandType = operand.getType();
|
||||
PsiTypeElement checkType = InstanceOfUtils.findCheckTypeElement(expression);
|
||||
CFGBuilder builder = new CFGBuilder(this);
|
||||
DfaVariableValue expressionValue;
|
||||
if (pattern == null) {
|
||||
if (checkType == null) {
|
||||
pushUnknown();
|
||||
@@ -1874,18 +1873,10 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
}
|
||||
}
|
||||
else if (operandType != null) {
|
||||
DfaValue expr = JavaDfaValueFactory.getExpressionDfaValue(getFactory(), operand);
|
||||
if (expr instanceof DfaVariableValue) {
|
||||
expressionValue = (DfaVariableValue)expr;
|
||||
builder.push(expressionValue);
|
||||
}
|
||||
else {
|
||||
expressionValue = createTempVariable(operand.getType());
|
||||
builder
|
||||
.pushForWrite(expressionValue)
|
||||
.pushExpression(operand)
|
||||
.assign();
|
||||
}
|
||||
builder
|
||||
.pushForWrite(createTempVariable(operand.getType()))
|
||||
.pushExpression(operand)
|
||||
.assign();
|
||||
processPatternInInstanceof(pattern, expression, operandType);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -2,6 +2,15 @@ import java.util.function.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class InstanceOfPattern {
|
||||
void test2(@Nullable Foo foo) {
|
||||
if (Math.random() > 0.5 && foo.<warning descr="Method invocation 'bar' may produce 'NullPointerException'">bar</warning>() instanceof String s) {
|
||||
System.out.println(s.length());
|
||||
}
|
||||
if (Math.random() > 0.5 && foo.<warning descr="Method invocation 'getBar' may produce 'NullPointerException'">getBar</warning>() instanceof String s) {
|
||||
System.out.println(s.length());
|
||||
}
|
||||
}
|
||||
|
||||
void test(Foo foo) {
|
||||
if (foo.bar() instanceof String s) {
|
||||
System.out.println(s.length());
|
||||
@@ -27,6 +36,8 @@ public class InstanceOfPattern {
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
@Nullable Object getBar();
|
||||
|
||||
@Nullable Object bar();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user