File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
java-checks-test-sources/src/main/java/checks
java-checks/src/main/java/org/sonar/java/checks Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -363,6 +363,29 @@ void bar() throws InterruptedException {
363
363
}
364
364
}
365
365
366
+ public void throwExceptionInTryDirectly () throws InterruptedException {
367
+ try {
368
+ throw new RuntimeException ();
369
+ } catch (Exception e ) { // Compliant
370
+ }
371
+
372
+ try {
373
+ throw new InterruptedException ();
374
+ } catch (Exception e ) { // Noncompliant
375
+ }
376
+
377
+ try {
378
+ InterruptedException ie = new InterruptedException ();
379
+ throw ie ;
380
+ } catch (Exception e ) { // Noncompliant
381
+ }
382
+
383
+ try {
384
+ throw getInterruptedException ();
385
+ } catch (Exception e ) { // Noncompliant
386
+ }
387
+ }
388
+
366
389
void falsePositivesSonarjava4406 () {
367
390
try {
368
391
try {
@@ -381,6 +404,15 @@ void falsePositivesSonarjava4406() {
381
404
} catch (Exception e ) { // Compliant, because inner try does not throw an InterruptedException
382
405
}
383
406
407
+ try {
408
+ try {
409
+ throwsInterruptedException ();
410
+ } catch (InterruptedException ie ) { // Compliant
411
+ throw new InterruptedException ();
412
+ }
413
+ } catch (Exception e ) { // Noncompliant, because inner try throws an InterruptedException
414
+ }
415
+
384
416
try {
385
417
try {
386
418
throwsInterruptedException ();
Original file line number Diff line number Diff line change @@ -179,6 +179,15 @@ public void visitTryStatement(TryStatementTree tryStatementTree) {
179
179
scan (tryStatementTree .catches ());
180
180
scan (tryStatementTree .finallyBlock ());
181
181
}
182
+
183
+ @ Override
184
+ public void visitThrowStatement (ThrowStatementTree tree ) {
185
+ // besides to method invocation, we also need to collect throw statements
186
+ if (isInterruptingExceptionExpression (tree .expression ())) {
187
+ invocationTree .add (tree );
188
+ }
189
+ super .visitThrowStatement (tree );
190
+ }
182
191
}
183
192
184
193
private static class BlockVisitor extends BaseTreeVisitor {
You can’t perform that action at this time.
0 commit comments