Author: bayard
Date: Mon Nov 12 11:58:30 2007
New Revision: 594278
URL: http://svn.apache.org/viewvc?rev=594278&view=rev
Log:
Applying the synchronization from LANG-369
Modified:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
Modified:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java?rev=594278&r1=594277&r2=594278&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
(original)
+++
commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
Mon Nov 12 11:58:30 2007
@@ -123,7 +123,9 @@
if (StringUtils.isNotEmpty(methodName) &&
!isCauseMethodName(methodName)) {
List list = getCauseMethodNameList();
if (list.add(methodName)) {
- CAUSE_METHOD_NAMES = toArray(list);
+ synchronized(CAUSE_METHOD_NAMES) {
+ CAUSE_METHOD_NAMES = toArray(list);
+ }
}
}
}
@@ -140,7 +142,9 @@
if (StringUtils.isNotEmpty(methodName)) {
List list = getCauseMethodNameList();
if (list.remove(methodName)) {
- CAUSE_METHOD_NAMES = toArray(list);
+ synchronized(CAUSE_METHOD_NAMES) {
+ CAUSE_METHOD_NAMES = toArray(list);
+ }
}
}
}
@@ -218,7 +222,9 @@
* @return [EMAIL PROTECTED] #CAUSE_METHOD_NAMES} as a List.
*/
private static ArrayList getCauseMethodNameList() {
- return new ArrayList(Arrays.asList(CAUSE_METHOD_NAMES));
+ synchronized(CAUSE_METHOD_NAMES) {
+ return new ArrayList(Arrays.asList(CAUSE_METHOD_NAMES));
+ }
}
/**
@@ -231,7 +237,9 @@
* @since 2.1
*/
public static boolean isCauseMethodName(String methodName) {
- return ArrayUtils.indexOf(CAUSE_METHOD_NAMES, methodName) >= 0;
+ synchronized(CAUSE_METHOD_NAMES) {
+ return ArrayUtils.indexOf(CAUSE_METHOD_NAMES, methodName) >= 0;
+ }
}
//-----------------------------------------------------------------------
@@ -267,7 +275,9 @@
* @since 1.0
*/
public static Throwable getCause(Throwable throwable) {
- return getCause(throwable, CAUSE_METHOD_NAMES);
+ synchronized(CAUSE_METHOD_NAMES) {
+ return getCause(throwable, CAUSE_METHOD_NAMES);
+ }
}
/**
@@ -295,7 +305,9 @@
Throwable cause = getCauseUsingWellKnownTypes(throwable);
if (cause == null) {
if (methodNames == null) {
- methodNames = CAUSE_METHOD_NAMES;
+ synchronized(CAUSE_METHOD_NAMES) {
+ methodNames = CAUSE_METHOD_NAMES;
+ }
}
for (int i = 0; i < methodNames.length; i++) {
String methodName = methodNames[i];
@@ -456,16 +468,18 @@
}
Class cls = throwable.getClass();
- for (int i = 0, isize = CAUSE_METHOD_NAMES.length; i < isize; i++) {
- try {
- Method method = cls.getMethod(CAUSE_METHOD_NAMES[i], null);
- if (method != null &&
Throwable.class.isAssignableFrom(method.getReturnType())) {
- return true;
+ synchronized(CAUSE_METHOD_NAMES) {
+ for (int i = 0, isize = CAUSE_METHOD_NAMES.length; i < isize; i++)
{
+ try {
+ Method method = cls.getMethod(CAUSE_METHOD_NAMES[i], null);
+ if (method != null &&
Throwable.class.isAssignableFrom(method.getReturnType())) {
+ return true;
+ }
+ } catch (NoSuchMethodException ignored) {
+ // exception ignored
+ } catch (SecurityException ignored) {
+ // exception ignored
}
- } catch (NoSuchMethodException ignored) {
- // exception ignored
- } catch (SecurityException ignored) {
- // exception ignored
}
}