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

String.hashCode() has a non-benign data race

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Introduced In Version:
      9
    • Resolved In Build:
      b139
    • CPU:
      generic
    • OS:
      generic

      Description

      Latest change to JDK 9 String code introduced a non-benign data race:

          public int hashCode() {
              if (hash == 0 && value.length > 0) {
                  hash = isLatin1() ? StringLatin1.hashCode(value)
                                    : StringUTF16.hashCode(value);
              }
              return hash;
          }

      The 'hash' field should only be read once into a local variable. The second racy read (at return) can read 0 while the 1st (at if) can read non-zero.

        Attachments

          Activity

            People

            • Assignee:
              plevart Peter Levart
              Reporter:
              plevart Peter Levart
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: