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


(ori marko) #1

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


public class MyServlet extends HttpServlet {
    private MySpringBean mySpringBean;

(Tibor Blenessy) #2

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