If l
is null
, then l.getRight()
will throw a null pointer exception.
You need to test whether l
is null
:
Node<E> lr = (l==null)?null:l.getRight();
That code will assign null
to lr
if l
is null
, and will assign l.getRight()
if l
is not null
.