-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RV_RETURN_VALUE_IGNORED should not be reported for methods annotated with '@com.google.errorprone.annotations.CanIgnoreReturnValue' #463
Comments
This bug appears when using the gradle plugin and using version |
Can you please pro ide a simple code example and what exactly is reported by SpotBugs? |
Probably related to #429 fix. |
Simple code example
Spotbug reports
Joiner.appendTo
|
I believe this has nothing to do with So what you probably want is that SpotBugs knows that such annotation exists and ignores the ignored return value if the called method is annotated with |
As I commented at #429 (comment) |
@KengoTODA in other issues it is being discussed that JSR305 is dead and should not be used. Spotbugs should know about this Annotation and treat it likewise. // Edit: Actually it was your own (correct) proposal for 4.0.0: So, better not introduce another dependency(?). |
Support for Guava annotations would indeed be very handy. |
Agreed; relying on JSR305 annotations is problematic. Amongst other things, the fact that JSR305 disbanded without producing an official spec means that the JAR everyone uses runs afoul of some of the Java licensing which restricts the use of the |
SpotBugs is FOSS, and any patches are welcome! :) I personally think that current workaround is enough especially for Guava; it already has dependency on JSR305. As permanent solution, I want to make progress on #421. |
Hi folks, This has caused some problems for us as we upgrade from FindBugs 3.0.1 to SpotBugs 3.1.1. Guava methods which didn't flag this detector now do. This is because #429 started respecting the annotation in package-info.java as explained in #429 (comment). We're going to have to suppress the whole detector now, until either this is fixed here or Guava changes their annotations. (I tried to suppress this error only for Guava classes, but it didn't work). |
In guava 23.6 they have migrated away from jsr305 to use annotations from Error Prone and Checker Framework. |
As @bhollis hinted, there appears to be no way to suppress |
Provide a patch which either allows the particular detector to know the particular annotation or adds the rule that |
Is there an extensibility mechanism in SpotBugs that allows us to implement that on version 3.1.0 as a workaround, or would that just be a patch for a new version? |
Something like this? diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/CheckReturnAnnotationDatabase.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/CheckReturnAnnotationDatabase.java
index 59dec70d5..05e7fa4ce 100644
--- a/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/CheckReturnAnnotationDatabase.java
+++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/CheckReturnAnnotationDatabase.java
@@ -292,6 +292,8 @@ public class CheckReturnAnnotationDatabase extends AnnotationDatabase<CheckRetur
.createClassDescriptor(CheckReturnValue.class);
private static final ClassDescriptor CHECK_RETURN_NULL_JSR305 = DescriptorFactory
.createClassDescriptor("javax/annotation/CheckReturnValue");
+ private static final ClassDescriptor CAN_IGNORE_RETURN_VALUE = DescriptorFactory
+ .createClassDescriptor("com/google/errorprone/annotations/CanIgnoreReturnValue");
private final Map<String, CheckReturnValueAnnotation> packageInfoCache = new HashMap<>();
@@ -338,6 +340,12 @@ public class CheckReturnAnnotationDatabase extends AnnotationDatabase<CheckRetur
return CheckReturnValueAnnotation.createFor(When.ALWAYS);
}
}
+
+ annotation = clazz.getAnnotation(CAN_IGNORE_RETURN_VALUE);
+ if (annotation != null) {
+ return CheckReturnValueAnnotation.createFor(When.NEVER);
+ }
+
return null;
}
} |
Methods annoted with
@com.google.errorprone.annotations.CanIgnoreReturnValue
generate anRV_RETURN_VALUE_IGNORED
error.For example
com.google.common.base.Stopwatch#start
causes this issue.The text was updated successfully, but these errors were encountered: