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:
parent
9926e31ac1
commit
ba320a3bc7
|
@ -123,7 +123,9 @@ public static void addCauseMethodName(String methodName) {
|
|||
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 @@ public static void removeCauseMethodName(String methodName) {
|
|||
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 @@ private static String[] toArray(List list) {
|
|||
* @return {@link #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 @@ private static ArrayList getCauseMethodNameList() {
|
|||
* @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 @@ public static boolean isCauseMethodName(String methodName) {
|
|||
* @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 @@ public static Throwable getCause(Throwable throwable, String[] methodNames) {
|
|||
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 @@ public static boolean isNestedThrowable(Throwable throwable) {
|
|||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue