S1118 demands a redundant private constructor on private nested class

java

(Daniel Forssten) #1

Version used: 6.7.3 (build 38370)

This seems to be a false-positive. Sonar wants a private constructor even though the private nested class Foo.Bar cannot be instantiated from anywhere outside the parent Foo class.

public class Foo {

    private static final class Bar {  // squid:1118 - Add a private constructor to hide the implicit public one.

// Uncomment constructor to resolve warning in Sonar, but then Intellij will warn with "Redundant no-arg constructor"
//        private Bar() {
//            // Should not be instantiated
//        }

        public static String bar1() {
            return "bar1";
        }
    }
}

(Nicolas Peru) #2

This seems to be corresponding to that ticket https://jira.sonarsource.com/browse/SONARJAVA-2562 that was solved quite some time ago. What is the SonarJava version installed on your sonarqube server ? or if it is in SonarLint what is the version of sonarlint you are using ?


(Daniel Forssten) #3

I don’t know which versions of SonarJava and SonarLint that we’re using, and I can’t find it anywhere in SonarQube’s UI. Presumably it’s whatever came with the installation of 6.7.3 (build 38370).