question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`@CheckReturnValue` decoration for `ApplicationContextAssert::getBean(s)` methods

See original GitHub issue

I 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:open
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sdeleuzecommented, Dec 5, 2022

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.

1reaction
wilkinsonacommented, Nov 18, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found