diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/IfStatementWithIdenticalBranchesInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/IfStatementWithIdenticalBranchesInspection.java index 132d88cfd5e8..814fee1e2edb 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/IfStatementWithIdenticalBranchesInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/IfStatementWithIdenticalBranchesInspection.java @@ -174,8 +174,8 @@ public class IfStatementWithIdenticalBranchesInspection @Override public void visitIfStatement(@NotNull PsiIfStatement ifStatement) { super.visitIfStatement(ifStatement); - final PsiStatement elseBranch = unwrap(ifStatement.getElseBranch()); - final PsiStatement thenBranch = unwrap(ifStatement.getThenBranch()); + final PsiStatement elseBranch = ifStatement.getElseBranch(); + final PsiStatement thenBranch = ifStatement.getThenBranch(); if (thenBranch == null) { return; } @@ -194,7 +194,9 @@ public class IfStatementWithIdenticalBranchesInspection } } - private boolean isDuplicate(@NotNull PsiElement element1, @NotNull PsiElement element2) { + private boolean isDuplicate(@NotNull PsiStatement element1, @NotNull PsiStatement element2) { + element1 = unwrap(element1); + element2 = unwrap(element2); final InputVariables inputVariables = new InputVariables(Collections.emptyList(), element1.getProject(), new LocalSearchScope(element1), false); final DuplicatesFinder finder = new DuplicatesFinder(new PsiElement[]{element1}, inputVariables, null, Collections.emptyList()); diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/if_statement_with_identical_branches/IfStatementWithIdenticalBranches.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/if_statement_with_identical_branches/IfStatementWithIdenticalBranches.java index 4c57ca5c142d..89b141cfdf73 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/if_statement_with_identical_branches/IfStatementWithIdenticalBranches.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/if_statement_with_identical_branches/IfStatementWithIdenticalBranches.java @@ -214,4 +214,14 @@ class NotADup { private Object bar(Object x) { return null; } + + void nesting(int i, int j) { + if (i == 2) { + System.out.println("2"); + } else { + if (j == 2) { + System.out.println("2"); + } + } + } }