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


(Iván Minguet García) #1

SonarLint IntelliJ

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) {