You also have to understand that the key will only work if you have the
exact same object instance for adding and retrieving from the map and the
key is not allowed to never change, because comparison will check if the
key is the same instance using equals() and hashCode().
article describes issues about using object as key in a hashmap.
Most likely, the problem you are facing is related to those