From 1a9d66091f217bb731e33818096a25e7db0fcc21 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Mon, 19 Nov 2018 14:51:19 +0700 Subject: [PATCH] ControlFlowAnalyzer#visitInstanceOfExpression: exclude check on unresolved type Otherwise red code `x instanceof Unresolved` produces also "always false" warning which is quite useless. --- .../dataFlow/ControlFlowAnalyzer.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java index cd0d5adfbd8a..2594a1ebb0c9 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java @@ -1606,17 +1606,21 @@ public class ControlFlowAnalyzer extends JavaElementVisitor { @Override public void visitInstanceOfExpression(PsiInstanceOfExpression expression) { startElement(expression); PsiExpression operand = expression.getOperand(); + operand.accept(this); PsiTypeElement checkType = expression.getCheckType(); - if (checkType != null) { - operand.accept(this); - PsiType type = checkType.getType(); - if (type instanceof PsiClassType) { - type = ((PsiClassType)type).rawType(); - } + PsiType type = checkType != null ? checkType.getType() : null; + if (type instanceof PsiClassType) { + type = ((PsiClassType)type).rawType(); + } + boolean validInstanceOf = type != null && + (!(type.getDeepComponentType() instanceof PsiClassType) || + PsiUtil.resolveClassInType(type.getDeepComponentType()) != null); + if (validInstanceOf) { addInstruction(new PushInstruction(myFactory.createTypeValue(type, Nullability.NOT_NULL), null)); addInstruction(new InstanceofInstruction(expression, operand, type)); } else { + addInstruction(new PopInstruction()); pushUnknown(); }