Im working on a right rotate method for when i splay. I have nodes that i use to hold the value of the left child and the left childs right. On the case that im testing the left childs right is null but when i compile i get a null pointer exception. Even if the value is null shouldnt it just assign the new node to null rather than throw a null pointer exception?
below are my assignments
Node<E> leftC = x.getLeft();
Node<E> leftsRight = leftC.getRight();
in the case im testing, the tree looks like
3
/
2
/
1
and x is 3, so then leftC is 2 and leftsRight should be null but it just throws the null pointer.
Why is it throwing the null pointer instead of just assigning it to null?