4 Replies Latest reply on Jul 10, 2012 10:16 PM by jschellSomeoneStoleMyAlias

    Strange behaviour with shorthand null check

      Today I had a strange occurance of a NPE with that code:

      SomeType type = (person.getType() != null ? TYPE1 : _ TYPE_2);

      When person is not null but person.getType() returns null, I always faced a NullPointerException. Changing the code to

      SomeType type = (person.getType() == null ? TYPE2 : _ TYPE_1);

      solved the problem and worked. I'd like to know if anyone here can explain this strange behaviour.



      Edited by: user4174452 on 05.07.2012 22:22