as it is mentioned in the book that "the line in the put method that updates the root." and "As methods may rearrange the tree structure, such methods return the node that ought to be the new root of the subtree." but there is no return statement in the put method in the BSTNode class, so every even time when the put method is called it is updating the root which looses the references of the nodes inserted before. to solve that i tried removing the update statement instead just call the put method this solved the issue for me.
as it is mentioned in the book that "the line in the put method that updates the root." and "As methods may rearrange the tree structure, such methods return the node that ought to be the new root of the subtree." but there is no return statement in the put method in the BSTNode class, so every even time when the put method is called it is updating the root which looses the references of the nodes inserted before. to solve that i tried removing the update statement instead just call the put method this solved the issue for me.