Issue Details (XML | Word | Printable)

Key: LANG-334
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Michael Sclafani
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Commons Lang

Enum is not thread-safe

Created: 14/May/07 10:30 PM   Updated: 05/Sep/07 10:14 AM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 2.4

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works 334.patch 2007-07-28 04:14 AM Jason Madden 2 kB
Java Source File Licensed for inclusion in ASF works EnumPlay.java 2007-06-06 03:24 PM Henri Yandell 1 kB

Resolution Date: 05/Sep/07 10:14 AM


 Description  « Hide
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.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #572930 Wed Sep 05 10:13:49 UTC 2007 bayard Applying Jason Madden's patch from LANG-334 to provide enums.Enum with optimized thread safety. As Jason's used this in production I think it's fair to use it rather than the simpler Collections.synchronizedMap(..). I've also applied the patch to the enum.Enum
Files Changed
MODIFY /commons/proper/lang/trunk/src/java/org/apache/commons/lang/enum/Enum.java
MODIFY /commons/proper/lang/trunk/src/java/org/apache/commons/lang/enums/Enum.java