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

java.time.temporal.ValueRange has poor hashCode()

XMLWordPrintable

    • b06
    • Not verified

        The hash code is currently implemented as
        {code}
            public int hashCode() {
                long hash = minSmallest + minLargest << 16 + minLargest >> 48 + maxSmallest << 32 +
                    maxSmallest >> 32 + maxLargest << 48 + maxLargest >> 16;
                return (int) (hash ^ (hash >>> 32));
            }
        {code}

        Since addition has higher precedence, the hash value is almost always is zero.
        (E.g. >> (32 + maxLargest) swaps away at least half of all the bits).

        The fix is to add some parentheses.

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

                Created:
                Updated:
                Resolved: