Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-334

Enum is not thread-safe

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.4
    • None
    • None

    Description

      Enum uses no synchronization. Even if you assume that instances are only declared statically, the cEnumClasses map is global and can be written to when a thread triggers static initialization of B.class while some other thread is doing getEnumList(A.class). Unsynchronized access of a map undergoing mutation is not thread-safe.

      This isn't theoretical. We're seeing ValuedEnum.getEnum(X.class, 0) return null after returning the correct value over 100,000 times, and then return the correct value again on the next invocation.

      Attachments

        1. 334.patch
          2 kB
          Jason Madden
        2. EnumPlay.java
          1 kB
          Henri Yandell

        Activity

          People

            Unassigned Unassigned
            sclafani Michael Sclafani
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: