java:S3749 false positive when the injection constructor delegates with "this(...)"

What language is this for? Java

Which rule? java:S3749, Members of Spring components should be injected

Why do you believe it’s a false-positive?

S3749 treats a field as injected when its identifier appears in the body of an injection constructor, which is either a constructor annotated with an injection annotation (@Autowired, @Inject, …) or the class’s only constructor. The check does not follow explicit constructor invocations. When the injection constructor delegates with this(...) to another constructor that assigns the fields, those fields are reported, even though Spring injects them through the annotated constructor.

Delegating to a canonical constructor is a common way to keep one place that validates and assigns fields while still offering a convenience or test constructor. It has been valid since Java 1.0. Java 25’s flexible constructor bodies (JEP 513), which allow statements such as argument validation before this(...), make it more common.

The existing test fixture S3749_DefaultAnnotations.java has no case with this(...). The closest related tickets are SONARJAVA-3153 (fields injected via constructor), whose fix this case falls just outside, and SONARJAVA-4646 (setter injection), which covers a similar gap where injection happens outside the code the rule inspects.

Are you using

  • SonarQube Server Enterprise Edition 2026.5.2 (build 132813)

How can we reproduce the problem?

import java.time.Clock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class S3749Repro {

  private final Object dependency; // Noncompliant: S3749 raised here (FP)
  private final Clock clock;       // Noncompliant: S3749 raised here (FP)

  @Autowired
  public S3749Repro(Object dependency) {
    this(dependency, Clock.systemUTC());
  }

  S3749Repro(Object dependency, Clock clock) {
    this.dependency = dependency;
    this.clock = clock;
  }
}

Expected: no issue. Spring calls the @Autowired constructor, which assigns both fields through this(...).

Actual: S3749 is raised on dependency and clock.

The same issue is raised with a Java 25 flexible constructor body:

@Autowired 
public S3749Repro(Object dependency) {
    java.util.Objects.requireNonNull(dependency, "dependency cannot be null");
    this(dependency, Clock.systemUTC());
}

Suggested fix: in SpringComponentWithNonAutowiredMembersCheck.symbolsUsedInConstructors, when an injection constructor contains a this(...) invocation, also collect identifiers from the target constructor, recursively, guarding against cycles.