In general, keys in hashmaps should be immutable .
See this
Note: great care must be exercised if mutable objects are used as map
keys. The behavior of a map is not specified if the value of an object
is changed in a manner that affects equals comparisons while the
object is a key in the map.
The hash of your key is calculated once during insert, the hashmap stores the it and it will not get automatically updated once your key is modified. That's why there's an a assumption that keys will be immutable.
Your options are:
1. Don't use mutable objects as keys. Try to find another key, or use an immutable part of your former key object
2. Don't change your mutable objects while they are used as keys