Affects PMD Version:7.0.0-rc1
Rule: UnnecessaryConstructor
Please provide the rule name and a link to the rule documentation:
https://docs.pmd-code.org/latest/pmd_rules_java_codestyle.html#unnecessaryconstructor
Description:
The first code sample uses the annotation com.google.inject.Inject
, and the second one uses javax.inject.Inject
. The analysis results of the two cases should be equivalent because these two annotations are equivalent. However, PMD reports a warning in the first sample and no warnings in the second one. Actually, PMD should not report a warning in Case 1
like the Case 2
because it has a injection here.
The exact same issue applies to Spring's @Autowired
.
Code Sample demonstrating the issue:
Case 1
import com.google.inject.Inject; public class Foo { private Foo() {} } public class Bar extends Foo { @Inject public Bar() {} // report a warnning }
Case 2
import javax.inject.Inject; public class Foo { private Foo() {} } public class Bar extends Foo { @Inject public Bar() {} // report no warnning }
Expected outcome: PMD reports a violation at line 8 in the first sample, but that's wrong. That's a false positive. PMD should report no violation if PMD sees com.google.inject.Inject
.
Running PMD through: CLI
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4