diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/SimplifiableIfStatementInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/SimplifiableIfStatementInspection.java index 5a449665a12f..919e77d293d9 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/SimplifiableIfStatementInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/SimplifiableIfStatementInspection.java @@ -320,11 +320,19 @@ public class SimplifiableIfStatementInspection extends BaseInspection { if (thenReturn == null) { return false; } + final PsiType thenType = thenReturn.getType(); + if (!PsiType.BOOLEAN.equals(thenType)) { + return false; + } final PsiExpression elseReturn = ((PsiReturnStatement)elseBranch).getReturnValue(); if (elseReturn == null) { return false; } + final PsiType elseType = elseReturn.getType(); + if (!PsiType.BOOLEAN.equals(elseType)) { + return false; + } final boolean thenConstant = BoolUtils.isFalse(thenReturn) || BoolUtils.isTrue(thenReturn); final boolean elseConstant = BoolUtils.isFalse(elseReturn) || @@ -368,10 +376,18 @@ public class SimplifiableIfStatementInspection extends BaseInspection { if (thenRhs == null) { return false; } + final PsiType thenRhsType = thenRhs.getType(); + if (!PsiType.BOOLEAN.equals(thenRhsType)) { + return false; + } final PsiExpression elseRhs = elseExpression.getRExpression(); if (elseRhs == null) { return false; } + final PsiType elseRhsType = elseRhs.getType(); + if (!PsiType.BOOLEAN.equals(elseRhsType)) { + return false; + } final boolean thenConstant = BoolUtils.isFalse(thenRhs) || BoolUtils.isTrue(thenRhs); final boolean elseConstant = BoolUtils.isFalse(elseRhs) || diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/simplifiable_if_statement/SimplifiableIfStatement.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/simplifiable_if_statement/SimplifiableIfStatement.java index b7a1c00dd0c2..e90a8fb4e6a0 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/simplifiable_if_statement/SimplifiableIfStatement.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/simplifiable_if_statement/SimplifiableIfStatement.java @@ -82,4 +82,21 @@ public class SimplifiableIfStatement { return c || d; } + + Boolean wrong1(int i) { + if (i == 3) { + return null; + } + return false; + } + + void wrong2(int i) { + Boolean a; + if (i == 3) { + a = null; + } else { + a = false; + } + } + } \ No newline at end of file