null cannot be automatically unpacked with a primitive boolean value, which is what happens when you try to compare it to true . IN
param == true
true is boolean , so the left operand must also be boolean . You pass a boolean , which is an object, but can be automatically unboxed to boolean .
Therefore it is equivalent
param.booleanValue() == true
It is clear that if param is null , then a NullPointerException .
To avoid the hidden traps of automatic unlocking, you could work with boolean objects:
if (Boolean.TRUE.equals(param)) return "a"; if (Boolean.FALSE.equals(param)) return "b"; return "c";
source share