Support for defaults in "Factory method injection should be used in "@Configuration" classes" rule

Running Sonar over this code:

public class SomethingConfiguration {
	@Autowired(required = false)
	private @NonNull List<Thing> things = Collections.emptyList();

	public Widget widget() {
		return new Widget(things);

Gives this false positive violation:

[rank 3] [java:S3305] /home/candrews/projects/Dashboard/src/main/java/mil/af/kesselrun/appops/mattermost/
  Factory method injection should be used in "@Configuration" classes


This violation should not occur when there’s an initializer on the @Autowired field (= Collections.emptyList(); in this example) because that’s how non-null defaults are accomplished. For reference, see

I’m using sonarlint version

Hello @candrews,

Thanks for the feedback and sorry for the delay.

It makes sense to me, ticket created: SONARJAVA-3605.


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