diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java index 0a6ef31fcc7e..e98ce28efeb6 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java @@ -43,9 +43,9 @@ public class PlaceholderCountMatchesArgumentCountInspection extends BaseInspecti @NotNull @Override protected String buildErrorString(Object... infos) { - final int argumentCount = ((Integer)infos[0]).intValue(); - final int placeholderCount = ((Integer)infos[1]).intValue(); - if (argumentCount > placeholderCount) { + final Integer argumentCount = (Integer)infos[0]; + final Integer placeholderCount = (Integer)infos[1]; + if (argumentCount.intValue() > placeholderCount.intValue()) { return InspectionGadgetsBundle.message("placeholder.count.matches.argument.count.more.problem.descriptor", argumentCount, placeholderCount); } @@ -106,11 +106,21 @@ public class PlaceholderCountMatchesArgumentCountInspection extends BaseInspecti if (placeholderCount == argumentCount) { return; } - registerMethodCallError(expression, argumentCount, placeholderCount); + registerMethodCallError(expression, Integer.valueOf(argumentCount), Integer.valueOf(placeholderCount)); } private static boolean hasThrowableType(PsiExpression lastArgument) { - return InheritanceUtil.isInheritor(lastArgument.getType(), "java.lang.Throwable"); + final PsiType type = lastArgument.getType(); + if (type instanceof PsiDisjunctionType) { + final PsiDisjunctionType disjunctionType = (PsiDisjunctionType)type; + for (PsiType disjunction : disjunctionType.getDisjunctions()) { + if (!InheritanceUtil.isInheritor(disjunction, CommonClassNames.JAVA_LANG_THROWABLE)) { + return false; + } + } + return true; + } + return InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_LANG_THROWABLE); } public static int countPlaceholders(String value) { diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java index a5a246170b43..8b69ced5f811 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java @@ -59,4 +59,21 @@ public class PlaceholderCountMatchesArgumentCountInspectionTest extends LightIns "}" ); } + + public void testMultiCatch() { + doTest("import org.slf4j.*;\n" + + "class X {\n" + + " private static final Logger logger = LoggerFactory.getLogger( X.class );\n" + + " public void multiCatch() {\n" + + " try {\n" + + " method();\n" + + " } catch ( FirstException|SecondException e ) {\n" + + " logger.info( \"failed with first or second\", e );\n" + + " }\n" + + " }\n" + + " public void method() throws FirstException, SecondException {}\n" + + " public static class FirstException extends Exception { }\n" + + " public static class SecondException extends Exception { }\n" + + "}"); + } } \ No newline at end of file