diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/ControlFlowAnalyzer.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/ControlFlowAnalyzer.java
index 954079576e23..e6c755c6e679 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/ControlFlowAnalyzer.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/ControlFlowAnalyzer.java
@@ -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 {
diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/InstanceOfPattern.java b/java/java-tests/testData/inspection/dataFlow/fixture/InstanceOfPattern.java
index bd745f74c090..208bc65b79fe 100644
--- a/java/java-tests/testData/inspection/dataFlow/fixture/InstanceOfPattern.java
+++ b/java/java-tests/testData/inspection/dataFlow/fixture/InstanceOfPattern.java
@@ -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.bar() instanceof String s) {
+ System.out.println(s.length());
+ }
+ if (Math.random() > 0.5 && foo.getBar() 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();
}
}
\ No newline at end of file