Skip to content
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

UnusedMethod is reported for JUnit @BeforeEach and for Java validation annotated methods #2881

Closed
sergeykad opened this issue Jan 21, 2022 · 1 comment

Comments

@sergeykad
Copy link
Contributor

sergeykad commented Jan 21, 2022

The problem observed with error-prone 2.10.0

The problem is reported for methods with well-known annotations like org.junit.jupiter.api.BeforeEach, javax.validation.constraints.AssertTrue and com.fasterxml.jackson.annotation.JsonProperty

The reported methods are indeed not used directly by our code, but by a dependency, like JUnit 5 or Jackson. It seems crude to annotate every such method with @SuppressWarnings("UnusedMethod")

There is a similar problem with "Unused variable" reported for class members annotated with org.springframework.boot.test.mock.mockito.MockBean.

@cushon
Copy link
Collaborator

cushon commented Jan 25, 2022

Both of those checks have heuristics with lists of annotations they recognize as meaning the variable or method isn't actually unused:

I'm happy to take PRs adding annotations to those lists.

Also FYI the next release of Error Prone will have a @Keep annotation that can be applied to other annotations, which will suppress those warnings on annotated elements. Not all projects are going to want to or be able to depend on Error Prone's annotations, but it provides an extensible way to add this kind of suppression.

copybara-service bot pushed a commit that referenced this issue Sep 21, 2023
Partially fixes #2881

Fixes #2947

FUTURE_COPYBARA_INTEGRATE_REVIEW=#2947 from sergeykad:unused_variable a41b7e3
PiperOrigin-RevId: 567318426
copybara-service bot pushed a commit that referenced this issue Sep 21, 2023
Partially fixes #2881

Fixes #2947

FUTURE_COPYBARA_INTEGRATE_REVIEW=#2947 from sergeykad:unused_variable a41b7e3
PiperOrigin-RevId: 567318426
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants