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

Use Long.hashCode() instead of int-cast where applicable

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 18
    • Component/s: core-libs
    • Labels:
      None
    • Resolved In Build:
      b19

      Description

      In some JDK classes there's still the following hashCode() implementation:

      long objNum;

      public int hashCode() {
          return (int) objNum;
      }

      This outdated expression should be replaced with Long.hashCode(long) as it

      - uses all bits of the original value, does not discard any information upfront. For example, depending on how you are generating the IDs, the upper bits could change more frequently (or the opposite).

      - does not introduce any bias towards values with more ones (zeros), as it would be the case if the two halves were combined with an OR (AND) operation.

      See also https://stackoverflow.com/a/4045083

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              stsypanov Sergey Tsypanov
              Reporter:
              stsypanov Sergey Tsypanov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: