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

Poor quality of sun.security.util.Cache.EqualByteArray.hashCode()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 10
    • None
    • security-libs
    • None

      The hashCode() doesn't depend on the relative order of the bytes in the underlying array.

          Cache.EqualByteArray a1 = new Cache.EqualByteArray(new byte[] {1,2,3});
          Cache.EqualByteArray a2 = new Cache.EqualByteArray(new byte[] {2,3,1});
          Cache.EqualByteArray a3 = new Cache.EqualByteArray(new byte[] {3,1,2});
          System.out.println(a1.hashCode());
          System.out.println(a2.hashCode());
          System.out.println(a3.hashCode());

      Prints
      226
      226
      226

      It may be better to use Arrays.hashCode(byte[]).

            igerasim Ivan Gerasimov
            igerasim Ivan Gerasimov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: