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

equals doesn't works in Hashtable and other collections for array element(s)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 7
    • core-libs

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      If in one collection for example Hashtable we add some array value as element, then the equals method of that collections doesn't works. This is because in the implementation for arrays are not used special equals methods from java.util.Arrays.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Create you own equals method where before value.equals(t.get(key)) is used the following code:

              if(source instanceof boolean[])
                  return Arrays.equals((boolean[])source, (boolean[])target);
              else if (source instanceof byte[])
                  return Arrays.equals((byte[])source, (byte[])target);
              else if (source instanceof char[])
                  return Arrays.equals((char[])source, (char[])target);
              else if (source instanceof double[])
                  return Arrays.equals((double[])source, (double[])target);
              else if (source instanceof float[])
                  return Arrays.equals((float[])source, (float[])target);
              else if (source instanceof int[])
                  return Arrays.equals((int[])source, (int[])target);
              else if (source instanceof long[])
                  return Arrays.equals((long[])source, (long[])target);
              else if (source instanceof short[])
                  return Arrays.equals((short[])source, (short[])target);
              else if (source instanceof Object[])
                  return Arrays.equals((Object[])source, (Object[])target);

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: