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

java.lang.UUID compareTo() does not do an unsigned compare

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 6u24
    • core-libs
    • x86
    • windows_7

      FULL PRODUCT VERSION :
      1.6.0_22

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7

      A DESCRIPTION OF THE PROBLEM :
      Found that UUID.compareTo() was producing results inconsistent other UUID comparison implementations including the rfc4122 sample implementation. Examined source:

      public int compareTo(UUID val) {
          // The ordering is intentionally set up so that the UUIDs
          // can simply be numerically compared as two numbers
          return (this.mostSigBits < val.mostSigBits ? -1 :
                  (this.mostSigBits > val.mostSigBits ? 1 :
                   (this.leastSigBits < val.leastSigBits ? -1 :
                    (this.leastSigBits > val.leastSigBits ? 1 :
                     0))));
      }

      It appears that, because mostSigBits and leastSigBits are stored as java longs, that this is a signed comparison when these values should be compared unsigned.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Perform bytewise comparison of UUID value.

            mduigou Mike Duigou
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: