Using Spring constructor injection with SonarQube
Check-out the SonarQube rule RSPEC-4288: Spring components should use constructor injection. Although it doesn't explain why the final
usage is triggered as non-compliant, there is a compliant code sample. Initialize the fields as null
to make it SonarQube compliant:
private Environment env = null;
private YYYAdaptor yyyAdaptor = null;
private JAXBContext jaxbContext = null;
However, what SonarQube says is not sacred and is filled with lots of false-positives. These static-analyzers hits the issues that are worth the further introspection, yet not definitive and based on the rules made by people with opinions.
Personally, I'd mark this issue as won't fix and declare the fields as final
to make the object immutable:
private final Environment env;
private final YYYAdaptor yyyAdaptor;
private final JAXBContext jaxbContext;