From b088cbd746912fc877c359e37a7bec14cc32e1cd Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 11 May 2020 22:00:34 +0200 Subject: [PATCH] NPE GitOrigin-RevId: cac6587190e100352e1302cfda0d3f09903724d6 --- .../src/com/intellij/psi/util/RedundantCastUtil.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/psi/util/RedundantCastUtil.java b/java/java-analysis-impl/src/com/intellij/psi/util/RedundantCastUtil.java index 61bf32fd4960..7e9794fe0680 100644 --- a/java/java-analysis-impl/src/com/intellij/psi/util/RedundantCastUtil.java +++ b/java/java-analysis-impl/src/com/intellij/psi/util/RedundantCastUtil.java @@ -84,7 +84,7 @@ public class RedundantCastUtil { } } - private void addIfNarrowing(PsiTypeCastExpression castExpression, PsiType opType, PsiType expectedTypeByParent) { + private void addIfNarrowing(PsiTypeCastExpression castExpression, @NotNull PsiType opType, PsiType expectedTypeByParent) { PsiTypeElement castElement = castExpression.getCastType(); if (castElement != null && TypeConversionUtil.isAssignable(castElement.getType(), opType, false) && (expectedTypeByParent == null || TypeConversionUtil.isAssignable(expectedTypeByParent, opType, false))) { @@ -97,7 +97,10 @@ public class RedundantCastUtil { if (expression instanceof PsiTypeCastExpression) { PsiExpression operand = getInnerMostOperand(expression); if (operand != null) { - addIfNarrowing((PsiTypeCastExpression)expression, operand.getType(), expectedTypeByParent); + PsiType opType = operand.getType(); + if (opType != null) { + addIfNarrowing((PsiTypeCastExpression)expression, opType, expectedTypeByParent); + } } } } @@ -786,7 +789,9 @@ public class RedundantCastUtil { return; } } - addIfNarrowing((PsiTypeCastExpression)switchVariable, opType, null); + if (opType != null) { + addIfNarrowing((PsiTypeCastExpression)switchVariable, opType, null); + } } } }