[ 
https://issues.apache.org/jira/browse/COLLECTIONS-872?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17903889#comment-17903889
 ] 

Gary D. Gregory commented on COLLECTIONS-872:
---------------------------------------------

Hello [~chrimle]

The new test {{MultiKeyMapTest.testCompress872()}} works in git master:
{code:java}
    @Test
    public void testCompress872() {
        final AtomicReference<String> k1 = new AtomicReference<>("K1v1");
        final AtomicReference<String> k2 = new AtomicReference<>("K2v1");
        final MultiKeyMap<AtomicReference<String>, String> map = 
(MultiKeyMap<AtomicReference<String>, String>) makeObject();
        assertNull(map.put(k1, k2, "V"));
        assertEquals("V", map.get(k1, k2));
        k1.set("K1v2");
        assertEquals("V", map.get(k1, k2));
        assertEquals("V", map.get(k1, k2));
    }
{code}

Please provide a failing unit test.


> 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: 2.0, 2.1, 2.1.1, 3.0, 3.1, 3.2, 3.2.1, 3.2.2, 
> 4.0-alpha1, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5.0-M1, 4.5.0-M2
>            Reporter: Christopher Molin
>            Priority: Critical
>
> 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, V 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