jeudi 19 avril 2018

NullPointerException when checking null on if condition with &&

For the following line of code:

if (user == null && user.getEmail() == null)

I expect it to check if user == null, and if it's true, to do the lines in the if. If it's not null, to check user.getEmail().

Sonar and IDEA gives the error: "A "NullPointerException" could be thrown; "user" is nullable here."

How could I fix it ?

Aucun commentaire:

Enregistrer un commentaire