throwable never thrown: exclude usages as method arguments

This commit is contained in:
anna
2010-07-19 22:45:45 +04:00
parent 522561d40c
commit 032068c1bd
3 changed files with 17 additions and 2 deletions
@@ -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);
@@ -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<IOException> exs = new ArrayList<IOException>();
exs.add(new IOException());
IOException io2 = new IOException();
exs.add(io2);
methodCall(io2);
}
void methodCall(IOException e){}
}
@@ -3,14 +3,14 @@
<problem>
<file>ThrowableInstanceNeverThrown.java</file>
<line>14</line>
<line>17</line>
<problem_class>Throwable instance not thrown</problem_class>
<description>Runtime exception instance &lt;code&gt;new RuntimeException()&lt;/code&gt; is not thrown</description>
</problem>
<problem>
<file>ThrowableInstanceNeverThrown.java</file>
<line>31</line>
<line>34</line>
<problem_class>Throwable instance not thrown</problem_class>
<description>Runtime exception instance &lt;code&gt;new RuntimeException(&quot;throw me&quot;)&lt;/code&gt; is not thrown</description>
</problem>