Index: src/java/org/apache/commons/lang/exception/ExceptionUtils.java =================================================================== --- src/java/org/apache/commons/lang/exception/ExceptionUtils.java (revision 753650) +++ src/java/org/apache/commons/lang/exception/ExceptionUtils.java (working copy) @@ -56,9 +56,13 @@ */ static final String WRAPPED_MARKER = " [wrapped] "; + // Lock object for CAUSE_METHOD_NAMES + private static final Object CAUSE_METHOD_NAMES_LOCK = new Object(); + /** *
The names of methods commonly used to access a wrapped exception.
*/ + //@GuardedBy("CAUSE_METHOD_NAMES_LOCK") private static String[] CAUSE_METHOD_NAMES = { "getCause", "getNextException", @@ -123,7 +127,7 @@ if (StringUtils.isNotEmpty(methodName) && !isCauseMethodName(methodName)) { List list = getCauseMethodNameList(); if (list.add(methodName)) { - synchronized(CAUSE_METHOD_NAMES) { + synchronized(CAUSE_METHOD_NAMES_LOCK) { CAUSE_METHOD_NAMES = toArray(list); } } @@ -142,7 +146,7 @@ if (StringUtils.isNotEmpty(methodName)) { List list = getCauseMethodNameList(); if (list.remove(methodName)) { - synchronized(CAUSE_METHOD_NAMES) { + synchronized(CAUSE_METHOD_NAMES_LOCK) { CAUSE_METHOD_NAMES = toArray(list); } } @@ -222,7 +226,7 @@ * @return {@link #CAUSE_METHOD_NAMES} as a List. */ private static ArrayList getCauseMethodNameList() { - synchronized(CAUSE_METHOD_NAMES) { + synchronized(CAUSE_METHOD_NAMES_LOCK) { return new ArrayList(Arrays.asList(CAUSE_METHOD_NAMES)); } } @@ -237,7 +241,7 @@ * @since 2.1 */ public static boolean isCauseMethodName(String methodName) { - synchronized(CAUSE_METHOD_NAMES) { + synchronized(CAUSE_METHOD_NAMES_LOCK) { return ArrayUtils.indexOf(CAUSE_METHOD_NAMES, methodName) >= 0; } } @@ -275,7 +279,7 @@ * @since 1.0 */ public static Throwable getCause(Throwable throwable) { - synchronized(CAUSE_METHOD_NAMES) { + synchronized(CAUSE_METHOD_NAMES_LOCK) { return getCause(throwable, CAUSE_METHOD_NAMES); } } @@ -305,7 +309,7 @@ Throwable cause = getCauseUsingWellKnownTypes(throwable); if (cause == null) { if (methodNames == null) { - synchronized(CAUSE_METHOD_NAMES) { + synchronized(CAUSE_METHOD_NAMES_LOCK) { methodNames = CAUSE_METHOD_NAMES; } } @@ -468,7 +472,7 @@ } Class cls = throwable.getClass(); - synchronized(CAUSE_METHOD_NAMES) { + synchronized(CAUSE_METHOD_NAMES_LOCK) { for (int i = 0, isize = CAUSE_METHOD_NAMES.length; i < isize; i++) { try { Method method = cls.getMethod(CAUSE_METHOD_NAMES[i], (Class[]) null);