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

False positive "Unnecessary @Autowired" warning when using abstract classes #985

Closed
pietro-saccani opened this issue Mar 2, 2023 · 1 comment
Assignees
Labels
for: eclipse something that is specific for Eclipse for: vscode something that is specific for VSCode theme: validation type: bug

Comments

@pietro-saccani
Copy link

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.

@BoykoAlex
Copy link
Contributor

@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

Should be fixed with 9cf2d7e

You could try STS4 eclipse snapshot update site tomorrow (see http://dist.springsource.com/snapshot/STS4/nightly-distributions.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: eclipse something that is specific for Eclipse for: vscode something that is specific for VSCode theme: validation type: bug
Projects
None yet
Development

No branches or pull requests

3 participants