`@CheckReturnValue` decoration for `ApplicationContextAssert::getBean(s)` methods
See original GitHub issueI suggest to decorate ApplicationContextAssert::getBean(s)
methods with a @CheckReturnValue
annotation so that incomplete statements like the following are spotted by static analysis tools like SpotBugs and IntelliJ IDEA:
assertThat(context).getBean(MyService.class);
To achieve this, no additional dependency is needed and Spring Boot Test can declare its own @CheckReturnValue
annotation, similarly to what AssertJ and Mockito do.
I can raise a PR with the changes if the idea is accepted.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
CheckReturnValue - Error Prone
The @CheckReturnValue annotation (available in JSR-305 or in Error Prone) marks methods whose return values must be used. This error is triggered when...
Read more >CheckReturnValue annotation applied to package is ... - GitHub
The RV_RETURN_VALUE_IGNORED_BAD_PRACTICE rule detects whether methods that are marked @CheckReturnValue have their return value ignored, ...
Read more >apply CheckReturnValue to entire project - java - Stack Overflow
Working from the understanding that Java garbage collection is based on object instance reference counting, that only instances with a reference ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This could be connected to https://github.com/spring-projects/spring-framework/issues/28797 (tentatively planned for 6.1) if we extends its scope via https://github.com/jspecify/jspecify/issues/200.
Thanks for the suggestion, @scordio. Using
@CheckReturnValue
sounds like a good option in this particular case. However, I wonder if we have other APIs where a similar annotation would be beneficial. A bit like nullability annotations for Kotlin, handling this inconsistently may create more problems than it solves. Flagging for team attention to see what everyone else thinks.