Hello,
I'm using the Initialization-on-demand-holder-pattern for thread-safe singletons.
public class MySingleton
{
private MySingleton()
{
// use getInstance()
}
private static class InitializationOnDemandHolderMySingleton {
static final MySingleton INSTANCE = new MySingleton();
}
public static MySingleton getInstance()
{
return InitializationOnDemandHolderMySingleton.INSTANCE;
}
SonarQube marks the private static class to add a private constructor to hide the implicit public one.
But a private constructor in a private class doesn't make any difference. The class MySingleton is the only one to which the private static class is visible - and MySingleton is the only class that would ever be able to initialize that static class (but never will) - no matter if the constructor is private or public.
So, why is this marked as an issue? I'd suggest that private classes won't be marked with issues of squid:s1118 as private constructors won't change anything here (except adding useless code) - or am I missing something?
Thanks, cheers,
Stefan.