False fault 'Null pointers should not be dereferenced' using Optional

java

(Iván Minguet García) #1

SonarLint IntelliJ 4.0.0.2916

Java Rule ‘Null pointers should not be dereferenced’

I’m getting this fault in the next code when obj can’t be null in any scenario. Seems the analizer don’t recognice the logic with the funcional object Optional.

final Obj obj = Optional.ofNullable(oldObj).orElse(new Obj());

if (obj.getSomeProperty() == null) {