Java

Java

Made by DeepSource

Local variable is assigned null value and not read after JAVA-W1040

Anti-pattern
Minor

A local variable is assigned null, and no reads of that variable occur after this assignment.

Such an assignment may have been done to help along the garbage collector, but this has been unnecessary since Java 6, where the garbage collector got a lot smarter.

Current JVMs are likely to optimize away assignments that are not used, meaning there is no net difference.

Bad Practices

String username = ...;

// ...

username = null;

// username is not used again.

In the example above, the final assignment to username is not followed by any other operation.

Recommended

If this assignment was only used to set a final null value, consider removing it.

References