Mutable HashMap Keys
A mutable object is dangerous as a HashMap key when its fields used by equality or hashing can change after insertion. If the object's hash code changes, the HashMap may search for it in a different bucket than the one where the entry was originally stored, making the value difficult or impossible to retrieve.
Hash-based lookup depends on the key's hash value.
Changing equality-relevant state can change the bucket mapping.
The entry may remain physically stored in its old bucket.
Removal using the mutated key may also fail.
Immutable keys are safer and easier to reason about.
If mutation is unavoidable, fields participating in equality and hashing should not change while the key is in the map.