I'm passing SonarLint on a somewhat old application and fixing several "problems", but I came across a code snippet like:
public void fazerAlgo(final String param) {
MeuObjeto m = new MeuObjeto();
m.setVar(param.toLowerCase());
myBusiness.atualizarAlgumaCoisa(m);
m = null; // <- Para liberar memória e ajudar o GC
}
And SonarLint accused the following error for line m = null
:
Remove this useless assignment to local variable
(Remova essa atribuição inútil à variável local)
The sonar point of view is that this object "m"
is not used after the assignment, so the set
becomes useless, this makes sense and in other code points where this happened I removed the assignment.
But at the time of Java 5, Java 6 (or many companies today), it was common for more advanced developers to ask for things like "put final
at all", "always start an array with a size "and" overrides objects before exiting the method, "the latter being to save memory and make the