harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jimmy,Jing Lv" <firep...@gmail.com>
Subject [classlib[luni] Delete LinkedHashMap's un-documented method "clone()" ? (Re: [jira] Created: (HARMONY-4603) [classlib][util] LinkedHashMap.clone() has problem when override the removeEldestEntry method)
Date Wed, 08 Aug 2007 07:03:50 GMT
Hi,

    According to Harmony-4603, there's a bug in LinkedHashMap.clone(),
it seems RI omit something (in detail, checking removeEldestEntry() )
while Harmony perform different. It can be fixed easily.
    However I have another finding that, the Spec never asks
LinkedHashMap(which extends HashMap) to override clone() but Harmony
does, as HashMap.clone() copies entries in arrays while LinkedHashMap
put them one by one : they appear different in behaviours.
     Deeper look into the code, I find a way to avoid this redundant
overriding and make Harmony exactly follow Spec. We can make a package
method putImpl() (which already exsists in HashMap) which do some real
work for put elements into maps, and override this putImpl in
LinkedHashMap. In clone method we can invoke putImpl to do
elements-copy(do different in HashMap and LinkedHashMap). In this way
we can both fix Harmony-4603 and delete LinkedHashMap's redundant
clone.
     The refactor has passed testcases, I have a little concern about
performance, it seems the older clone() in HashMap may have higher
performance. I'll run benchmarks to determin and try to tuning if so.
     If no objection and it still have high performance, I'll patch
them together in Harmony-4603.

2007/8/7, Sean Qiu (JIRA) <jira@apache.org>:
> [classlib][util] LinkedHashMap.clone() has problem when override the removeEldestEntry
method
> ---------------------------------------------------------------------------------------------
>
>                  Key: HARMONY-4603
>                  URL: https://issues.apache.org/jira/browse/HARMONY-4603
>              Project: Harmony
>           Issue Type: Bug
>           Components: Classlib
>             Reporter: Sean Qiu
>
>
>  LinkedHashMap.clone() has problem when override the removeEldestEntry method
>
> ===== Test =====
> public class LinkedHashMapTest extends TestCase {
>     public void test_clone() {
>         LinkedHashMap hashMap = new MockMap();
>         String value = "value a";
>         hashMap.put("key", value);
>         MockMap cloneMap = (MockMap) hashMap.clone();
>         assertEquals(value, cloneMap.get("key"));
>         assertEquals(hashMap, cloneMap);
>         assertEquals(1, cloneMap.num);
>
>         hashMap.put("key", "value b");
>         assertFalse(hashMap.equals(cloneMap));
>     }
>
>     class MockMap extends LinkedHashMap {
>         int num;
>
>         public Object put(Object k, Object v) {
>             num++;
>             return super.put(k, v);
>         }
>
>         protected boolean removeEldestEntry(Map.Entry e) {
>             return num > 1;
>         }
>     }
> }
>
> === Result ===
> RI:           Pass
> Harmy:   Fail
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>


-- 

Best Regards!

Jimmy, Jing Lv
China Software Development Lab, IBM

Mime
View raw message