//'main' method must be in a class 'Rextester'.
//openjdk version '11.0.5'
import java.util.*;
import java.lang.*;
class Rextester
{
public static void main(String args[])
{
Integer a = null, b = null;
Integer c = a != null && b != null ? Math.min(a,b) : (a != null ? a : (b != null ? b : null));
}
}
I am completely baffled as to how this is returning a null pointer exception. Integer typesa
&& b
are both set to null. c
should return null, but a null pointer exception is thrown.
This does not occur when a
and b
are set to arbitrary values.
This means the second ternary operation is failing (a != null ? a : (b != null ? b : null));
What is the reason behind this? Is there something I am missing.