S2226 should not raise issues for field annotated with @Autowire in Servlet

I’m auto-wiring Spring bean in Servlets, SonarQube is warning that “all servlet fields should then be either static and/or final”

But it similar false positive as SONARJAVA-2744 which was Java’s @Inject

Code:

public class MyServlet extends HttpServlet {
    @Autowire
    private MySpringBean mySpringBean;
}

Indeed the issue should not be raised on such field same way as it is not raised on field annotated with @Inject, @Resource or @EJB.

I created an issue to fix this https://jira.sonarsource.com/browse/SONARJAVA-2895

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.