How do I mark Java methods as “must use results” for static analysis?
When compiling C or C with GCC, you can mark functions with attributes ((warn_unused_result)). If you call a function that returns something and then don't assign it to anything, the compiler will complain
There are some methods in the Java library I developed. There are such methods - calling them and discarding them always results in a bug I hope API users can identify such errors through static analysis, such as checking with findbugs or IntelliJ
I wonder if there is a method comment that is usually used to mark a method or function as "must use results" Findbugs provides some special bug finding programs for the standard library, but the general method will be very useful
Solution
There is completely a standard comment, which is @ checkreturnvalue Findbugs owns it; See, for example, here
Guava uses it internally – for example, in the configuration methods for splitter – from JSR 305