Ok. Let's try in this way
public static void main(String[] args){
System.out.println(withTernary(null, null));
}
private static Boolean withTernary(String val, Boolean defVal){
return (val == null ? defVal : Boolean.valueOf("true".equalsIgnoreCase(val)));
}
Now it will works fine. Now there is no unboxing here and will not give you exception.
But in other way due to null unbox you will get NPE
public static void main(String[] args){
System.out.println(withTernary(null, null)); //Null Pointer
}
private static Boolean withTernary(String val, Boolean defVal){
return (val == null ? defVal : "true".equalsIgnoreCase(val));
}