False positive java:S6832

Make sure to read this post before raising a thread here:

Then tell us:

  • What language is this for? java
  • Which rule? S6832
  • Why do you believe it’s a false-positive/false-negative?

Without having the complete ApplicationContext in hand the rule can hardly decide whether the class is a “Singleton” in it. But I believe the rule should report it only, if there is a clear indication of the problem.

  • Are you using
    • SonarCloud? no
    • SonarQube - which version? no
    • SonarLint - which IDE/version? yes ( with IntelliJ IDEA 2023.3.4 Build #IU-233.14475.28
      • in connected mode with SonarQube or SonarCloud? no
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

In the below example no injection in RandomClassWhichIsNotBean:

public class NonSingletonAutowiredInSingletonCheckSample {

    public class PrototypeBean {

    public class RandomClassWhichIsNotBean {
        RandomClassWhichIsNotBean(PrototypeBean prototypeBean) {


As far as i could dig into the rule, i can see the following: If there isn’t any annotation on the class, the below method (hasNotSingletonScopeAnnotation) will return false, which marks the RandomClassWhichIsNotBean as a “Singleton”. But there is no evidence whether this class will play any role in the lifecycle of the ApplicationContext.