Skip to content

Commit d9aea4f

Browse files
committed
Fix MethodReturnCheck Ex thrown
1 parent 4b46444 commit d9aea4f

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2547Test.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ void testIssue() {
2121
"ghIssues/issue2547/MyEx.class",
2222
"ghIssues/issue2547/ExceptionFactory.class");
2323

24-
assertBug(3);
24+
assertBug(2);
2525
assertBug("notThrowingExCtor", 15);
2626
assertBug("notThrowingExCtorCaller", 26);
27-
assertBug("notThrowingExCtorCallerOutside", 37);
2827
}
2928

3029
private void assertBug(int num) {

spotbugs/src/main/java/edu/umd/cs/findbugs/detect/MethodReturnCheck.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,10 @@ private void sawMethodCallWithIgnoredReturnValue() {
317317
SignatureParser methodSigParser = new SignatureParser(methodDescriptor.getSignature());
318318
String returnTypeSig = methodSigParser.getReturnTypeSignature();
319319
String returnType = ClassName.fromFieldSignature(returnTypeSig);
320+
String mContainerClass = methodDescriptor.getClassDescriptor().getClassName();
320321
if (returnType != null
321322
&& Subtypes2.instanceOf(ClassName.toDottedClassName(returnType), Values.DOTTED_JAVA_LANG_THROWABLE)
322-
&& !("initCause".equals(methodDescriptor.getName()) && methodSigParser.getArguments().length == 1
323-
&& "Ljava/lang/Throwable;".equals(methodSigParser.getArguments()[0]))
324-
&& !("getCause".equals(methodDescriptor.getName()) && methodSigParser.getArguments().length == 0)) {
323+
&& methodDescriptor.isStatic() && (returnType.equals(mContainerClass))) {
325324
BugInstance warning = new BugInstance(this, "RV_EXCEPTION_NOT_THROWN", 1).addClassAndMethod(this).addMethod(callSeen)
326325
.describe(MethodAnnotation.METHOD_CALLED);
327326
bugAccumulator.accumulateBug(warning, SourceLineAnnotation.fromVisitedInstruction(this, callPC));

spotbugsTestCases/src/java/ghIssues/issue2547/Issue2547.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public void createAndThrowExCtorCaller() throws MyEx {
3232
throw e;
3333
}
3434

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

0 commit comments

Comments
 (0)