I would suggest that either your tree is deformed or really big. There seems to be no problems with the code.
If your tree is deformed in such a way that you have a Node
inserted twice in the same tree then this code will break.
Added - You are eating a little more stack than you need - replacing p.left.getHeight()
with getHeight(p.left)
etc. would avoid one stack push per recursion. If your issue is merely big tree then this might scrape you through but this would only postpone the problem.