diff -u -r org.orig/apache/commons/lang/enums/Enum.java org/apache/commons/lang/enums/Enum.java
--- org.orig/apache/commons/lang/enums/Enum.java 2007-02-09 22:16:48.000000000 -0600
+++ org/apache/commons/lang/enums/Enum.java 2007-07-27 10:00:21.000000000 -0500
@@ -302,7 +302,12 @@
/**
* Map, key of class name, value of Entry.
*/
- private static final Map cEnumClasses = new WeakHashMap();
+ private static Map cEnumClasses
+ //Bug 334: To avoid exposing a mutating map,
+ //we copy it each time we add to it. This is cheaper than
+ //using a synchronized map since we are almost entirely reads
+ //TODO: should this be valatile?
+ = new WeakHashMap();
/**
* The string representation of the Enum.
@@ -395,18 +400,23 @@
if (ok == false) {
throw new IllegalArgumentException("getEnumClass() must return a superclass of this class");
}
-
- // create entry
- Entry entry = (Entry) cEnumClasses.get(enumClass);
- if (entry == null) {
- entry = createEntry(enumClass);
- cEnumClasses.put(enumClass, entry);
+ Entry entry;
+ synchronized( Enum.class ) { //Bug 334
+ // create entry
+ entry = (Entry) cEnumClasses.get(enumClass);
+ if (entry == null) {
+ entry = createEntry(enumClass);
+ Map myMap = new WeakHashMap( cEnumClasses );
+ myMap.put(enumClass, entry);
+ cEnumClasses = myMap;
+ }
}
if (entry.map.containsKey(name)) {
throw new IllegalArgumentException("The Enum name must be unique, '" + name + "' has already been added");
}
entry.map.put(name, this);
entry.list.add(this);
+
}
/**