Christopher Molin created COLLECTIONS-872:
---------------------------------------------

             Summary: MultiKeyMap: Key-objects are stored as reference, making 
it possible to modify the Map externally
                 Key: COLLECTIONS-872
                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-872
             Project: Commons Collections
          Issue Type: Bug
          Components: Map
    Affects Versions: 4.5.0-M2, 4.5.0-M1, 4.4, 4.3, 4.2, 4.1, 4.0, 4.0-alpha1, 
3.2.2, 3.2.1, 3.2, 3.1, 3.0, 2.1.1, 2.1, 2.0
            Reporter: Christopher Molin


When using MultiKeyMap, the keys are stored as-is (as references).

This leads to the following problem:
 # Create a MultiKeyMap, with key(s) of a type (class/record) which has some 
fields.
 # Use multiKeyMap.put(T... keys, R value), to create an entry in the Map, to 
map the keys to a value
 # Use multiKeyMap.get(T... keys), to verify that the mapping exists and 
returns the expected value.
 # Modify/alter any of the objects used as a key. It is enough to change the 
value of any member field of any of the objects.
 # Use multiKeyMap.get(T... keys) again, however, now there is no mapping for 
these keys!
 # Use multiKeyMap.get(T... keys) with the new modified/altered objects, and it 
will return the expected value

This is potentially a major issue - especially for those unaware of this 
behavior!

 

This is a problem since the introduction in v1.17

 

Potential Solution:

Calculate the Hash of the keys, and use those as keys. This way, would not be 
subject to external modification.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to