squid:UnusedPrivateMethod false positive when used on static inner classes

java

(Joe Swanson) #1

Sonarqube v 7.4 (build 18908)
SonarJava v 5.8 (build 15699)
sonar-maven-plugin v 3.5.0.1254

When using the sonarLint plugin in intellij and analyze the below code (minorly modified for ease of illustration), no issues arise. However, when the maven sonar plugin pushes statistics to our sonarqube server, it reports that the private constructor in CarryoutIntentResponse is not used. It is clearly used. If we remove it the code doesn’t compile, so it is clearly used. Yet every single time we apply this particular pattern (static inner class extending an abstract class with a private constructor) it is flagged with squid:UnusedPrivateMethod.

public abstract class OrderIntentResponse extends IntentResponse {
    private int startIndex;

    public OrderIntentResponse(String type) {
        super(type);
    }
}


public abstract class CarryoutIntentResponse extends OrderIntentResponse {
    private CarryoutIntentResponse(String type) {
        super(type);
    }

    public static class Failed extends CarryoutIntentResponse {
        public Failed(String type) {
            super(type);
        }
    }

    public static class FailedDueNoZip extends Failed {
        public FailedDueNoZip() {
            super("NO_ZIP");
        }
    }

    public static class Success extends CarryoutIntentResponse {
        public Success(OrderDetail orderDetail) {
            super("CARRYOUT_SUCCESS");
            // other business logic
        }
    }
}