harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Hindess (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-5788) [classlib][util] TreeMap.entrySet().contains() returns true for entries with null value
Date Mon, 28 Apr 2008 14:43:55 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-5788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12592817#action_12592817
] 

Mark Hindess commented on HARMONY-5788:
---------------------------------------

Jimmy, The "v1 == null" test is effectively "TreeMap.this.get(entry.getKey()) == null" but
this test does not allow us to distinguish the case where the entry is null from the case
where the key does not exist.  So I think we should leave the return line alone but those
lines with a containsKey condition to rule out one of the two ambiguous cases.  Like:

                public boolean contains(Object object) {
                    if (object instanceof Map.Entry) {
                        Map.Entry<K, V> entry = (Map.Entry<K, V>) object;
                        K key = entry.getKey();
                        if (TreeMap.this.containsKey(key)) {
                            Object v1 = TreeMap.this.get(key),
                                   v2 = entry.getValue();
                            return v1 == null ? v2 == null : v1.equals(v2);
                        }
                    }
                    return false;
                }

Does this make sense?  I'm going to run some more tests and wait for your comments before
committing it.



> [classlib][util] TreeMap.entrySet().contains() returns true for entries with null value
> ---------------------------------------------------------------------------------------
>
>                 Key: HARMONY-5788
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5788
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Mark Hindess
>
> The following code illustrates the problem:
> import java.util.TreeMap;
> public class TestTreeMap {
>     public static void main(String[] args) {
>         TreeMap master = new TreeMap<String, String>();
>         master.put("one", "1");
>         master.put("null", null);
>         TreeMap map = new TreeMap<String, String>();
>         Object[] element = master.entrySet().toArray();
>         for (int i = 0; i < element.length ; i++) {
>             System.out.println("Contains entry " + element[i] + "? == " +
>                                map.entrySet().contains(element[i]));
>         }
>     }
> }
> On harmony, the output is:
>   Contains entry null=null? == true
>   Contains entry one=1? == false
> on the RI, the output is:
>   Contains entry null=null? == false
>   Contains entry one=1? == false

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message