ClassVariableVisibilityCheck on collection

I have following class:

import java.util.LinkedList;
import java.util.List;

public class SomeClass
{
   public List<String> someList = new LinkedList<>();
}

This gives me ClassVariableVisibilityCheck which says I could make this final static (I would like to avoid adding accessors). But when I do this, I still have minor vulnerability (just like before) - S2386 - which says to make it protected. So I anyway need to end up having accesors.

In that case it makes no sense to apply rule which says that I can make this static final :frowning:

I’m using SonarLint 3.6 for Eclipse.

Hello @noelo,

Indeed I think in your case if you want to keep a mutable list you should have it private and have accessors for external use. This is a way to keep class encapsulated.
I agree that rule ClassVariableVisibilityCheck raising a message Make ... a static final constant or non-public and provide accessors if needed. is not perfect here as first option (making it static final) will not be good enough and S2386 will report.
So I believe in the case like yours rule ClassVariableVisibilityCheck should report with message Make ... a non-public and provide accessors if needed.