According to a comment from this post, hascode of null objects can throw NPE or a value of zero. This is implementation speci
hascode
null objects
throw NPE
zero
As the javadoc says:
Objects.hashCode(Object o) Returns the hash code of a non-null argument and 0 for a null argument.
Objects.hashCode(Object o)
Returns the hash code of a non-null argument and 0 for a null argument.
p2.hashCode() throws a NullPointerException because you are trying to access a method of a null object.
p2.hashCode()
NullPointerException