@CheckReturnValue currently only targets ElementType.METHOD. IDEs, however, also consider a type-level @CheckReturnValue to express that all methods' return values should be checked. I would appreciate it if our annotation could be used that way, too.

It would also make sense to allow the usage of the annotation on constructors and packages, the latter implying all methods in the package having to be checked.

Comment From: sdeleuze

I can see the value of adding it on types, for example for some builder style APIs, so I will add related target.

For other targets, I am not convinced for now we should support them.

While we support setting nullability at package level (default that makes sense for most cases), for @CheckReturnValue the use cases where that make sense looks much less frequent to me, could be surprising (you need to check package-info.java to know if this is enabled package wide) and our variant does not have (on purpose) a when attribute like the original JSR 305 variant to unset the package-level default.

For constructor, I have not been able to observe a concrete effect when setting it, IDEA gives me no warning, and I am unsure about the use case, so I prefer not adding it until we understand the purpose and use case.

I will target Spring Framework 7 milestones in order to get a chance to have feedback and potentially refine accordingly.

Comment From: sdeleuze

Hum, while doing more tests, I saw that type level @CheckReturnValue is not recognized by IntelliJ IDEA, so I prefer to dicuss that point with them before introducing it.

Comment From: odrotbohm

Hm, interesting. I could've sworn I had seen this working with the custom annotation I have defined in Spring Modulith. Turns out you're right. I guess I had derived it works from the type level due to JSR-305's @CheckReturnValue being declared with targets as proposed.

It looks like folks had asked for this in IDEA already, but the ticket got closed without comment.

Comment From: sdeleuze

I have created https://youtrack.jetbrains.com/issue/IDEA-374480/Support-CheckReturnValue-on-type-constructor-and-packages and brought that issue to the attention of the JetBrains team.

Comment From: sdeleuze

IDEA-374480 has been fixed, so let's add type and constructor target to @CheckReturnValue.