-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add @CanIgnoreReturnValue
annotations
#868
Add @CanIgnoreReturnValue
annotations
#868
Conversation
This cancels out the package-level `@CheckReturnValue` annotations introduced in ff12385 for selected builder-style methods.
caffeine/build.gradle
Outdated
@@ -122,6 +122,7 @@ tasks.named('compileJava').configure { | |||
dependsOn generateLocalCaches, generateNodes | |||
finalizedBy compileCodeGenJava | |||
options.errorprone.disable('CheckReturnValue') | |||
options.errorprone.error('CanIgnoreReturnValueSuggester') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might go into codeQuality.gradle?
caffeine/gradle/codeQuality.gradle
Lines 154 to 155 in d084f2d
options.errorprone { | |
def enabledChecks = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed that. Lemme try!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way it also flags some test code. That's fine; will add the annotations there too.
@kluever please review. I guess that I missed that this was added to all the build methods. I just want to confirm this is everyone's intent. |
I suppose we can also remove some of the suppressions that are now irrelevant. I think that would be CaffeinePolicy, CacheBuilderTest, and CacheBuilderFactory. |
Thanks for flagging. That actually uncovers that additional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved most @SuppressWarnings
; there remaining ones call a method whose return value should generally not be ignored. One more commit coming up.
@Override | ||
@CanIgnoreReturnValue | ||
public boolean remove(K key, V oldValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The annotation also applies to some other methods in this class; they're not flagged likely because there's no test calling them. I'll add a separate commit for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Mostly it is called by the jsr107 tck where our tests are to increase the code coverage due to possible gaps. The tck is a dependency that is unzipped during the build to run its tests, so a bit indirect and wouldn't be flagged.
@CanIgnoreReturnValue
annotations to non-test code@CanIgnoreReturnValue
annotations
Updated the PR title and suggested commit message, since the PR now also covers some test code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll merge and release once @kluever gives his blessing.
hey @kluever, sorry to bother you but can you please take a quick skim? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Do you want to add @CheckReturnValue
to the package-info.java (or alternatively, on each top-level type?)
@@ -123,7 +123,7 @@ public V apply(K key) { | |||
} | |||
|
|||
@Override | |||
@SuppressWarnings({"CheckReturnValue", "FutureReturnValueIgnored"}) | |||
@SuppressWarnings("FutureReturnValueIgnored") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally have been recommending just capturing into a var unused = ...
variable instead of using @SuppressWarnings(...)
. Up to you tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see 36 usages of @SuppressWarnings("FutureReturnValueIgnored")
. Happy to make this change, but perhaps this is better done in a separate PR. Will await @ben-manes' verdict :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer @SuppressWarnings
as other linters will flag unused variables (e.g. Eclipse). It's unfortunate as it does expand the suppression to the method instead of statement, but does a better job of avoiding warning spam. I'm open to revisiting to a better scheme separately so as to narrow the scope.
This was already done in ff12385 :) Assuming each package has such a file, all were modified: $ git grep -L CheckReturnValue -- '*package-info.java' | wc -l
0 |
Some packages lack a $ git ls-files '*.java' -- ':!:*module-info.java' | xargs dirname | sort -u | while read d; do test -f "${d}/package-info.java" || echo "${d}"; done
caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache
caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local
caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/node
caffeine/src/jmh/java/com/github/benmanes/caffeine
caffeine/src/jmh/java/com/github/benmanes/caffeine/cache
caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/impl
caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/sketch
caffeine/src/jmh/java/com/github/benmanes/caffeine/profiler
caffeine/src/test/java/com/github/benmanes/caffeine
caffeine/src/test/java/com/github/benmanes/caffeine/apache
caffeine/src/test/java/com/github/benmanes/caffeine/cache
caffeine/src/test/java/com/github/benmanes/caffeine/cache/buffer
caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues
caffeine/src/test/java/com/github/benmanes/caffeine/cache/stats
caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing
caffeine/src/test/java/com/github/benmanes/caffeine/eclipse
caffeine/src/test/java/com/github/benmanes/caffeine/eclipse/acceptance
caffeine/src/test/java/com/github/benmanes/caffeine/eclipse/mutable
caffeine/src/test/java/com/github/benmanes/caffeine/google
caffeine/src/test/java/com/github/benmanes/caffeine/jsr166
caffeine/src/test/java/com/github/benmanes/caffeine/lincheck
caffeine/src/test/java/com/github/benmanes/caffeine/testing
examples/coalescing-bulkloader/src/main/java/com/github/benmanes/caffeine/examples/coalescing/bulkloader
examples/coalescing-bulkloader/src/test/java/com/github/benmanes/caffeine/examples/coalescing/bulkloader
examples/write-behind-rxjava/src/main/java/com/github/benmanes/caffeine/examples/writebehind/rxjava
examples/write-behind-rxjava/src/test/java/com/github/benmanes/caffeine/examples/writebehind/rxjava
guava/src/test/java/com/github/benmanes/caffeine/guava
guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility
jcache/src/test/java/com/github/benmanes/caffeine/jcache
jcache/src/test/java/com/github/benmanes/caffeine/jcache/configuration
jcache/src/test/java/com/github/benmanes/caffeine/jcache/copy
jcache/src/test/java/com/github/benmanes/caffeine/jcache/event
jcache/src/test/java/com/github/benmanes/caffeine/jcache/expiry
jcache/src/test/java/com/github/benmanes/caffeine/jcache/integration
jcache/src/test/java/com/github/benmanes/caffeine/jcache/management
jcache/src/test/java/com/github/benmanes/caffeine/jcache/processor
jcache/src/test/java/com/github/benmanes/caffeine/jcache/size
jcache/src/test/java/com/github/benmanes/caffeine/jcache/spi
simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/address/penalties
simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient
simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill
simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/inference
simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/sim
simulator/src/test/java/com/github/benmanes/caffeine/cache/simulator/admission/bloom |
If you'd like to add to those other packages that would be fine, I think only the |
I'm always up for enabling more static analysis ;) My agenda for the rest of the week is pretty tight, though, so it might make sense to defer that work to a separate PR; I can't say right now when I'll get around to a new pass. |
Added another commit; as far as I can tell all packages now declare I noticed that a subset of the existing packages also declare nullability annotations (as well as a copyright header, in some cases); I left that out for now. If I should e.g. add those things to just the packages in the |
lgtm. We’re not using checker so it’s only for users, so probably unnecessary. You can merge once the ci passes 🙂 |
👍 Thanks for the quick review! Updated the suggested commit message to include this latest change. |
Released in 3.1.4 |
Suggested commit message:
Reason for filing this PR, is that when upgrading to Caffeine 3.1.3 our build fails with
The above error is triggered by this code:
(Our build has nearly all Error Prone checks enabled.)