commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Madden (JIRA)" <>
Subject [jira] Commented: (LANG-334) Enum is not thread-safe
Date Sat, 28 Jul 2007 04:15:53 GMT


Jason Madden commented on LANG-334:

We have also encountered the issue of thread safety in the Enum  
class. In our case, it shows up when running in a application server  
where there are many threads and other applications are loading  
classes at arbitrary times.

I've attached the patch that we are using which seems to correct this  
issue for us. Rather than synchronize all access to the cEnumClasses  
map (which seems like it would be rather expensive and highly  
contended), we adopted a copy-on-write approach that only involves  
synchronization when new classes are loaded.

> Enum is not thread-safe
> -----------------------
>                 Key: LANG-334
>                 URL:
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Michael Sclafani
>             Fix For: 2.3.1
>         Attachments: 334.patch,
> 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.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message