Author: sebb
Date: Fri May 25 14:58:39 2012
New Revision: 1342666
URL: http://svn.apache.org/viewvc?rev=1342666&view=rev
Log:
LANG-803 - LocaleUtils - DCL idiom is not thread-safe
Modified:
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/LocaleUtils.java
commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml
Modified:
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/LocaleUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/LocaleUtils.java?rev=1342666&r1=1342665&r2=1342666&view=diff
==============================================================================
---
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/LocaleUtils.java
(original)
+++
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/LocaleUtils.java
Fri May 25 14:58:39 2012
@@ -39,12 +39,6 @@ import java.util.Set;
*/
public class LocaleUtils {
- /** Unmodifiable list of available locales. */
- private static List cAvailableLocaleList; // lazily created by
availableLocaleList()
-
- /** Unmodifiable set of available locales. */
- private static Set cAvailableLocaleSet; // lazily created by
availableLocaleSet()
-
/** Unmodifiable map of language locales by country. */
private static final Map cLanguagesByCountry =
Collections.synchronizedMap(new HashMap());
@@ -191,22 +185,7 @@ public class LocaleUtils {
* @return the unmodifiable list of available locales
*/
public static List availableLocaleList() {
- if(cAvailableLocaleList == null) {
- initAvailableLocaleList();
- }
- return cAvailableLocaleList;
- }
-
- /**
- * Initializes the availableLocaleList. It is separate from
availableLocaleList()
- * to avoid the synchronized block affecting normal use, yet synchronized
and
- * lazy loading to avoid a static block affecting other methods in this
class.
- */
- private static synchronized void initAvailableLocaleList() {
- if(cAvailableLocaleList == null) {
- List list = Arrays.asList(Locale.getAvailableLocales());
- cAvailableLocaleList = Collections.unmodifiableList(list);
- }
+ return SyncAvoid.AVAILABLE_LOCALE_LIST;
}
//-----------------------------------------------------------------------
@@ -220,21 +199,7 @@ public class LocaleUtils {
* @return the unmodifiable set of available locales
*/
public static Set availableLocaleSet() {
- if(cAvailableLocaleSet == null) {
- initAvailableLocaleSet();
- }
- return cAvailableLocaleSet;
- }
-
- /**
- * Initializes the availableLocaleSet. It is separate from
availableLocaleSet()
- * to avoid the synchronized block affecting normal use, yet synchronized
and
- * lazy loading to avoid a static block affecting other methods in this
class.
- */
- private static synchronized void initAvailableLocaleSet() {
- if(cAvailableLocaleSet == null) {
- cAvailableLocaleSet = Collections.unmodifiableSet( new
HashSet(availableLocaleList()) );
- }
+ return SyncAvoid.AVAILABLE_LOCALE_SET;
}
//-----------------------------------------------------------------------
@@ -313,4 +278,19 @@ public class LocaleUtils {
return countries;
}
+ //-----------------------------------------------------------------------
+ // class to avoid synchronization (Init on demand)
+ static class SyncAvoid {
+ /** Unmodifiable list of available locales. */
+ static final List AVAILABLE_LOCALE_LIST;
+ /** Unmodifiable set of available locales. */
+ static final Set AVAILABLE_LOCALE_SET;
+
+ static {
+ List list = new
ArrayList(Arrays.asList(Locale.getAvailableLocales())); // extra safe
+ AVAILABLE_LOCALE_LIST = Collections.unmodifiableList(list);
+ AVAILABLE_LOCALE_SET = Collections.unmodifiableSet(new
HashSet(list));
+ }
+ }
+
}
Modified: commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml?rev=1342666&r1=1342665&r2=1342666&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml Fri May
25 14:58:39 2012
@@ -20,6 +20,9 @@
<title>Commons Lang Changes</title>
</properties>
<body>
+ <release version="2.7" date="TBA" description="TBA (requires minimum of Java
1.3)">
+ <action issue="LANG-803" type="fix">LocaleUtils - DCL idiom is not
thread-safe.</action>
+ </release>
<release version="2.6" date="2011-01-16" description="Bug Fixes/Enhancements
for the 2.6 release (requires minimum of Java 1.3)">
<action type="update" issue="LANG-633">BooleanUtils: use same optimization
in toBooleanObject(String) as in toBoolean(String)</action>