[java] UnusedPrivateMethod for methods annotated with jakarta.annotation.PostConstruct or PreDestroy #5117
Labels
a:false-positive
PMD flags a piece of code that is not problematic
Milestone
Affects PMD Version:
7.3.0
Rule:
UnusedPrivateMethod
Description:
UnusedPrivateMethod
should not be reported for methods annotated withjakarta.annotation.PostConstruct
orjakarta.annotation.PreDestroy
since they are usually called by a container (for example Spring).As a workaround, the annotations can be added to configuration:
However, I think such methods should be excluded by default.
Code Sample demonstrating the issue:
Expected outcome:
PMD reports a violation at lines 0 and 13, but that's wrong. That's a false positive.
Running PMD through: Gradle
The text was updated successfully, but these errors were encountered: