Applying the synchronization from LANG-369

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@594278 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2007-11-12 19:58:30 +00:00
parent 9926e31ac1
commit ba320a3bc7
1 changed files with 29 additions and 15 deletions

View File

@ -123,10 +123,12 @@ public static void addCauseMethodName(String methodName) {
if (StringUtils.isNotEmpty(methodName) && !isCauseMethodName(methodName)) { if (StringUtils.isNotEmpty(methodName) && !isCauseMethodName(methodName)) {
List list = getCauseMethodNameList(); List list = getCauseMethodNameList();
if (list.add(methodName)) { if (list.add(methodName)) {
synchronized(CAUSE_METHOD_NAMES) {
CAUSE_METHOD_NAMES = toArray(list); CAUSE_METHOD_NAMES = toArray(list);
} }
} }
} }
}
/** /**
* <p>Removes from the list of method names used in the search for <code>Throwable</code> * <p>Removes from the list of method names used in the search for <code>Throwable</code>
@ -140,10 +142,12 @@ public static void removeCauseMethodName(String methodName) {
if (StringUtils.isNotEmpty(methodName)) { if (StringUtils.isNotEmpty(methodName)) {
List list = getCauseMethodNameList(); List list = getCauseMethodNameList();
if (list.remove(methodName)) { if (list.remove(methodName)) {
synchronized(CAUSE_METHOD_NAMES) {
CAUSE_METHOD_NAMES = toArray(list); CAUSE_METHOD_NAMES = toArray(list);
} }
} }
} }
}
/** /**
* <p>Sets the cause of a <code>Throwable</code> using introspection, allowing * <p>Sets the cause of a <code>Throwable</code> using introspection, allowing
@ -218,8 +222,10 @@ private static String[] toArray(List list) {
* @return {@link #CAUSE_METHOD_NAMES} as a List. * @return {@link #CAUSE_METHOD_NAMES} as a List.
*/ */
private static ArrayList getCauseMethodNameList() { private static ArrayList getCauseMethodNameList() {
synchronized(CAUSE_METHOD_NAMES) {
return new ArrayList(Arrays.asList(CAUSE_METHOD_NAMES)); return new ArrayList(Arrays.asList(CAUSE_METHOD_NAMES));
} }
}
/** /**
* <p>Tests if the list of method names used in the search for <code>Throwable</code> * <p>Tests if the list of method names used in the search for <code>Throwable</code>
@ -231,8 +237,10 @@ private static ArrayList getCauseMethodNameList() {
* @since 2.1 * @since 2.1
*/ */
public static boolean isCauseMethodName(String methodName) { public static boolean isCauseMethodName(String methodName) {
synchronized(CAUSE_METHOD_NAMES) {
return ArrayUtils.indexOf(CAUSE_METHOD_NAMES, methodName) >= 0; return ArrayUtils.indexOf(CAUSE_METHOD_NAMES, methodName) >= 0;
} }
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
@ -267,8 +275,10 @@ public static boolean isCauseMethodName(String methodName) {
* @since 1.0 * @since 1.0
*/ */
public static Throwable getCause(Throwable throwable) { public static Throwable getCause(Throwable throwable) {
synchronized(CAUSE_METHOD_NAMES) {
return getCause(throwable, CAUSE_METHOD_NAMES); return getCause(throwable, CAUSE_METHOD_NAMES);
} }
}
/** /**
* <p>Introspects the <code>Throwable</code> to obtain the cause.</p> * <p>Introspects the <code>Throwable</code> to obtain the cause.</p>
@ -295,8 +305,10 @@ public static Throwable getCause(Throwable throwable, String[] methodNames) {
Throwable cause = getCauseUsingWellKnownTypes(throwable); Throwable cause = getCauseUsingWellKnownTypes(throwable);
if (cause == null) { if (cause == null) {
if (methodNames == null) { if (methodNames == null) {
synchronized(CAUSE_METHOD_NAMES) {
methodNames = CAUSE_METHOD_NAMES; methodNames = CAUSE_METHOD_NAMES;
} }
}
for (int i = 0; i < methodNames.length; i++) { for (int i = 0; i < methodNames.length; i++) {
String methodName = methodNames[i]; String methodName = methodNames[i];
if (methodName != null) { if (methodName != null) {
@ -456,6 +468,7 @@ public static boolean isNestedThrowable(Throwable throwable) {
} }
Class cls = throwable.getClass(); Class cls = throwable.getClass();
synchronized(CAUSE_METHOD_NAMES) {
for (int i = 0, isize = CAUSE_METHOD_NAMES.length; i < isize; i++) { for (int i = 0, isize = CAUSE_METHOD_NAMES.length; i < isize; i++) {
try { try {
Method method = cls.getMethod(CAUSE_METHOD_NAMES[i], null); Method method = cls.getMethod(CAUSE_METHOD_NAMES[i], null);
@ -468,6 +481,7 @@ public static boolean isNestedThrowable(Throwable throwable) {
// exception ignored // exception ignored
} }
} }
}
try { try {
Field field = cls.getField("detail"); Field field = cls.getField("detail");