forked from spotbugs/spotbugs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR fixes issue spotbugs#2040 by limiting the errors reported by the detector `ThrowingExceptions` to cases where `java.lang.Exception` or `lava.lang.Throwable` appears in the exception specification of th method but it is neither inherited from an overridden method nor is is coming from another method that the method invokes. Syntathic methods are also omitted as well as methods which throw generic exceptions.
- Loading branch information
Ádám Balogh
committed
May 30, 2022
1 parent
68e7dca
commit 191f62b
Showing
8 changed files
with
259 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2040Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package edu.umd.cs.findbugs.detect; | ||
|
||
import edu.umd.cs.findbugs.AbstractIntegrationTest; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; | ||
import org.junit.Test; | ||
|
||
import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class Issue2040Test extends AbstractIntegrationTest { | ||
@Test | ||
public void test() { | ||
performAnalysis("ghIssues/issue2040/Base.class", | ||
"ghIssues/issue2040/Derived.class", | ||
"ghIssues/issue2040/Interface.class", | ||
"ghIssues/issue2040/Generic.class", | ||
"ghIssues/issue2040/Caller.class"); | ||
BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder() | ||
.bugType("THROWS_METHOD_THROWS_CLAUSE_THROWABLE") | ||
.build(); | ||
assertThat(getBugCollection(), containsExactly(1, bugTypeMatcher)); | ||
|
||
bugTypeMatcher = new BugInstanceMatcherBuilder() | ||
.bugType("THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION") | ||
.build(); | ||
assertThat(getBugCollection(), containsExactly(1, bugTypeMatcher)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ghIssues.issue2040; | ||
|
||
public class Base { | ||
public void method() throws Throwable { | ||
throw new Throwable(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ghIssues.issue2040; | ||
|
||
public class Caller { | ||
public void method() throws Throwable { | ||
Base b = new Base(); | ||
b.method(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
spotbugsTestCases/src/java/ghIssues/issue2040/Derived.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ghIssues.issue2040; | ||
|
||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class Derived extends Base implements Interface, Callable<Integer> { | ||
@Override | ||
public void method() throws Throwable { | ||
super.method(); | ||
} | ||
|
||
@Override | ||
public void iMethod() throws Exception { | ||
return; | ||
} | ||
|
||
public <T extends Throwable> void genericMethod() throws T { | ||
|
||
} | ||
|
||
public Integer call() throws Exception { | ||
return 0; | ||
} | ||
|
||
public void lambda() { | ||
ExecutorService es = Executors.newCachedThreadPool(); | ||
es.submit(() -> { return null; }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ghIssues.issue2040; | ||
|
||
public class Generic<E extends Exception> { | ||
void method() throws E { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ghIssues.issue2040; | ||
|
||
public interface Interface { | ||
public void iMethod() throws Exception; | ||
} |