You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False positive "Unnecessary @Autowired" warning when using abstract classes #985
Hello, I'm on Eclipse; I'm using an abstract class with a certain constructor, and if in a class extending that one I put @Autowired on the constructor (that needs to call super(<arguments>) inside), STS flags that annotation as unnecessary.
If I remove it, though, an exception is thrown: org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter <type and name of the parameter> in constructor <description of the constructor>.
So, that annotation is for sure not unnecessary.
I don't know which class is responsible for this warning, but while I was looking for it I've noticed that the AutowiredConstructorReconciler class has a typo in it (says "Unnecesary", with one "s").
Here's a repo with a super simple project that reproduces the issue on STS 4.17.2.
The project contains two test classes: the abstract one whose constructor wants a RestTemplateBuilder argument (I simply used the first @bean type that came to my mind, could be anything else); the other class extends it and has @Autowired on the constructor.
If you try to execute the unit test, it will work. But if you remove that @Autowired as the warning says, you'll get the exception I mentioned above.
@pietro-saccani thanks very much for the detailed issue with example project!
AutowiredConstructorReconciler is a dead unused class. I have removed ii - thanks for bringing this up! This dead code was left in the repo for some time.
As for the false-positive. We exclude classes annotated with @SpringBootTest but didn't account that this annotation is inherited therefore i have enhanced the exclusion check to also test the super types for @SpringBootTest
Activity
BoykoAlex commentedon Mar 3, 2023
@pietro-saccani thanks very much for the detailed issue with example project!
AutowiredConstructorReconciler is a dead unused class. I have removed ii - thanks for bringing this up! This dead code was left in the repo for some time.
As for the false-positive. We exclude classes annotated with
@SpringBootTestbut didn't account that this annotation is inherited therefore i have enhanced the exclusion check to also test the super types for@SpringBootTestShould be fixed with 9cf2d7e
You could try STS4 eclipse snapshot update site tomorrow (see http://dist.springsource.com/snapshot/STS4/nightly-distributions.html)