commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <>
Subject [jira] Commented: (LANG-334) Enum is not thread-safe
Date Thu, 09 Aug 2007 07:03:43 GMT


Henri Yandell commented on LANG-334:

It's great that you've got a fix working in production Jason, the patch seems good to me.

Any thoughts Michael? I like the simplicity of using synchronizedMap, but the copy-on-write
optimization seems attractive.

And yeah... I've given up trying to replicate this :) I'd need to be using something like
cglib so I could generate new enum subclasses by the thousand and see if it hits the race
condition that way.

> 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.

View raw message