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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 9
    • core-libs
    • None
    • 9
    • b139
    • generic
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: