diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableInstanceNeverThrownInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableInstanceNeverThrownInspection.java index 043ea018f324..7d825378e8a5 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableInstanceNeverThrownInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ThrowableInstanceNeverThrownInspection.java @@ -83,6 +83,7 @@ public class ThrowableInstanceNeverThrownInspection extends BaseInspection { } else if (parent instanceof PsiReturnStatement) { return; } + if (PsiTreeUtil.getParentOfType(parent, PsiCallExpression.class) != null) return; final PsiElement typedParent = PsiTreeUtil.getParentOfType(expression, PsiAssignmentExpression.class, @@ -129,6 +130,7 @@ public class ThrowableInstanceNeverThrownInspection extends BaseInspection { } else if (usageParent instanceof PsiReturnStatement) { return; } + if (PsiTreeUtil.getParentOfType(usageParent, PsiCallExpression.class) != null) return; } } registerError(expression, expression); diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_instance_never_thrown/ThrowableInstanceNeverThrown.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_instance_never_thrown/ThrowableInstanceNeverThrown.java index b6445f7bf1da..f87fa95e2cae 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_instance_never_thrown/ThrowableInstanceNeverThrown.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_instance_never_thrown/ThrowableInstanceNeverThrown.java @@ -1,5 +1,8 @@ package com.siyeh.igtest.bugs.throwable_instance_never_thrown; +import java.io.IOException; +import java.util.*; + public class ThrowableInstanceNeverThrown { void foo() throws Exception { @@ -30,4 +33,14 @@ public class ThrowableInstanceNeverThrown { void leftBehind() throws Throwable { final RuntimeException e = new RuntimeException("throw me"); } + + void exceptionIsCollected() { + List exs = new ArrayList(); + exs.add(new IOException()); + IOException io2 = new IOException(); + exs.add(io2); + methodCall(io2); + } + + void methodCall(IOException e){} } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_instance_never_thrown/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_instance_never_thrown/expected.xml index 0c197b2f6208..9dfb5295b08f 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_instance_never_thrown/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_instance_never_thrown/expected.xml @@ -3,14 +3,14 @@ ThrowableInstanceNeverThrown.java - 14 + 17 Throwable instance not thrown Runtime exception instance <code>new RuntimeException()</code> is not thrown ThrowableInstanceNeverThrown.java - 31 + 34 Throwable instance not thrown Runtime exception instance <code>new RuntimeException("throw me")</code> is not thrown