vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Better quick fix to "Potential null pointer access": check if the variable is not null

Open rcsilva83 opened this issue 5 months ago • 1 comments

I have the following code:

String s = null;
// do conditional stuff with "s"
s.length() // "Potential null pointer access" warning

Currently VS Code offers me 2 quick fixes:

  1. "Ignore compiler problem(s)"
  2. "Add @SuppressWarnings 'null' to myMethod"

A better quick fix option would be to add a "not nulll" check before the method calling.

rcsilva83 avatar Jun 27 '25 13:06 rcsilva83