Skip to content

Commit

Permalink
Fix MethodReturnCheck Ex thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
JuditKnoll committed Oct 17, 2023
1 parent 0084a18 commit 8f07438
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ void testIssue() {
"ghIssues/issue2547/MyEx.class",
"ghIssues/issue2547/ExceptionFactory.class");

assertBug(3);
assertBug(2);
assertBug("notThrowingExCtor", 15);
assertBug("notThrowingExCtorCaller", 26);
assertBug("notThrowingExCtorCallerOutside", 37);
}

private void assertBug(int num) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,10 @@ private void sawMethodCallWithIgnoredReturnValue() {
SignatureParser methodSigParser = new SignatureParser(methodDescriptor.getSignature());
String returnTypeSig = methodSigParser.getReturnTypeSignature();
String returnType = ClassName.fromFieldSignature(returnTypeSig);
String mContainerClass = methodDescriptor.getClassDescriptor().getClassName();
if (returnType != null
&& Subtypes2.instanceOf(ClassName.toDottedClassName(returnType), Values.DOTTED_JAVA_LANG_THROWABLE)
&& !("initCause".equals(methodDescriptor.getName()) && methodSigParser.getArguments().length == 1
&& "Ljava/lang/Throwable;".equals(methodSigParser.getArguments()[0]))
&& !("getCause".equals(methodDescriptor.getName()) && methodSigParser.getArguments().length == 0)) {
&& methodDescriptor.isStatic() && (returnType.equals(mContainerClass))) {
BugInstance warning = new BugInstance(this, "RV_EXCEPTION_NOT_THROWN", 1).addClassAndMethod(this).addMethod(callSeen)
.describe(MethodAnnotation.METHOD_CALLED);
bugAccumulator.accumulateBug(warning, SourceLineAnnotation.fromVisitedInstruction(this, callPC));
Expand Down
3 changes: 2 additions & 1 deletion spotbugsTestCases/src/java/ghIssues/issue2547/Issue2547.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public void createAndThrowExCtorCaller() throws MyEx {
throw e;
}

// non-compliant
// This could be non-compliant, but it's a false negative currently.
// It needs a good heuristic to not cause too many FPs.
public void notThrowingExCtorCallerOutside() {
ExceptionFactory.createMyException(5);
}
Expand Down

0 comments on commit 8f07438

Please sign in to comment.