diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableInstanceNeverThrownInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableInstanceNeverThrownInspection.java index 4bd1070850dd..eabfb47dd205 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableInstanceNeverThrownInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableInstanceNeverThrownInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2010 Bas Leijdekkers + * Copyright 2007-2011 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.psiutils.TypeUtils; import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; public class ThrowableInstanceNeverThrownInspection extends BaseInspection { @@ -167,7 +168,8 @@ public class ThrowableInstanceNeverThrownInspection extends BaseInspection { (PsiMethodCallExpression) grandParent; final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); - final String methodName = methodExpression.getReferenceName(); + @NonNls final String methodName = + methodExpression.getReferenceName(); if (!"initCause".equals(methodName)) { return null; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspection.java index 3c83d5286c68..473892e76de7 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspection.java @@ -65,7 +65,8 @@ public class ThrowableResultOfMethodCallIgnoredInspection parent = parent.getParent(); } if (parent instanceof PsiReturnStatement || - parent instanceof PsiThrowStatement) { + parent instanceof PsiThrowStatement || + parent instanceof PsiExpressionList) { return; } if (!TypeUtils.expressionHasTypeOrSubtype(expression, diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/A.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/A.java new file mode 100644 index 000000000000..488651f5481b --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/A.java @@ -0,0 +1,18 @@ +package com.siyeh.igtest.bugs.throwable_result_of_method_call_ignored; + + + +public class A { + public static void test() { + try { + firstNonNull(new Throwable(), null); + } + catch (Exception e) { + throw new RuntimeException(firstNonNull(e.getCause(), e)); + } + } + + public static T firstNonNull(T first, T second) { + return first != null ? first : second; + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/expected.xml new file mode 100644 index 000000000000..a02d25eb9ecf --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/expected.xml @@ -0,0 +1,9 @@ + + + + A.java + 8 + Throwable result of method call ignored + Result of <code>firstNonNull()</code> not thrown #loc + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspectionTest.java new file mode 100644 index 000000000000..b976db0f9b0a --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspectionTest.java @@ -0,0 +1,12 @@ +package com.siyeh.ig.bugs; + +import com.siyeh.ig.IGInspectionTestCase; + +public class ThrowableResultOfMethodCallIgnoredInspectionTest + extends IGInspectionTestCase { + + public void test() throws Exception { + doTest("com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored", + new ThrowableResultOfMethodCallIgnoredInspection()); + } +}