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

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

    Details

    • Subcomponent:
    • Resolved In Build:
      b06
    • Verification:
      Not verified

      Backports

        Description

        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.

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: