Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5023830

Collections$CheckedMap$CheckedEntrySet defines equals(), but not hashCode()

XMLWordPrintable

      David Hovemeyer writes:

      H HE: java.util.Collections$CheckedMap$CheckedEntrySet defines equals and uses Object.hashCode()

      No hashCode method is defined for java.util.Collections$CheckedMap$CheckedEntrySet, will default to using
      Object.hashCode().

      This is a serious bug and needs to be fixed.

      Code showing problem:

      import java.util.*;

      class F {
        public static void main(String args[]) throws Exception {
              Map<String,String> m = new HashMap<String,String>();
              m.put("a","b");
              Set<Map.Entry<String,String>> s = m.entrySet();

              Map<String,String> m2 = Collections.checkedMap(m,
                                                      String.class, String.class);
              Set<Map.Entry<String,String>> s2 = m2.entrySet();
              System.out.println(m.hashCode());
              System.out.println(s.hashCode());
              System.out.println(m2.hashCode());
              System.out.println(s2.hashCode());
              }
      }

      Results (all should be the same):

      [cafe 5] java F
      3
      3
      3
      25675463

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: