JDK-8179086 : java.time.temporal.ValueRange has poor hashCode()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.time
  • Affected Version: 8,9,10
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2017-04-21
  • Updated: 2018-02-15
  • Resolved: 2017-04-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 8
10 b06Fixed 8u162Fixed
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.