You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by gg...@apache.org on 2005/02/24 21:42:55 UTC
svn commit: r155238 -
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
Author: ggregory
Date: Thu Feb 24 12:42:53 2005
New Revision: 155238
URL: http://svn.apache.org/viewcvs?view=rev&rev=155238
Log:
Fixes http://issues.apache.org/bugzilla/show_bug.cgi?id=33737.
[lang] ExceptionUtils.addCauseMethodName(String) does not check for duplicates.
Fix adds:
ExceptionUtils.removeCauseMethodName(String)
ExceptionUtils.isCauseMethodName(String)
Modified:
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java?view=diff&r1=155237&r2=155238
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java Thu Feb 24 12:42:53 2005
@@ -42,7 +42,7 @@
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @author Pete Gieser
* @since 1.0
- * @version $Id: ExceptionUtils.java,v 1.43 2004/10/21 01:18:33 ggregory Exp $
+ * @version $Id$
*/
public class ExceptionUtils {
@@ -103,14 +103,62 @@
* @since 2.0
*/
public static void addCauseMethodName(String methodName) {
+ if (StringUtils.isNotEmpty(methodName) && !isCauseMethodName(methodName)) {
+ List list = getCauseMethodNameList();
+ if (list.add(methodName)) {
+ CAUSE_METHOD_NAMES = toArray(list);
+ }
+ }
+ }
+
+ /**
+ * <p>Removes from the list of method names used in the search for <code>Throwable</code>
+ * objects.</p>
+ *
+ * @param methodName the methodName to remove from the list, <code>null</code>
+ * and empty strings are ignored
+ * @since 2.1
+ */
+ public static void removeCauseMethodName(String methodName) {
if (StringUtils.isNotEmpty(methodName)) {
- List list = new ArrayList(Arrays.asList(CAUSE_METHOD_NAMES));
- list.add(methodName);
- CAUSE_METHOD_NAMES = (String[]) list.toArray(new String[list.size()]);
+ List list = getCauseMethodNameList();
+ if (list.remove(methodName)) {
+ CAUSE_METHOD_NAMES = toArray(list);
+ }
}
}
/**
+ * Returns the given list as a <code>String[]</code>.
+ * @param list a list to transform.
+ * @return the given list as a <code>String[]</code>.
+ */
+ private static String[] toArray(List list) {
+ return (String[]) list.toArray(new String[list.size()]);
+ }
+
+ /**
+ * Returns {@link #CAUSE_METHOD_NAMES} as a List.
+ * @return {@link #CAUSE_METHOD_NAMES} as a List.
+ */
+ private static ArrayList getCauseMethodNameList() {
+ return new ArrayList(Arrays.asList(CAUSE_METHOD_NAMES));
+ }
+
+ /**
+ * <p>Tests if the list of method names used in the search for <code>Throwable</code>
+ * objects include the given name.</p>
+ *
+ * @param methodName the methodName to search in the list.
+ * @return if the list of method names used in the search for <code>Throwable</code>
+ * objects include the given name.
+ * @since 2.1
+ */
+ public static boolean isCauseMethodName(String methodName) {
+ return ArrayUtils.indexOf(CAUSE_METHOD_NAMES, methodName) >= 0;
+ }
+
+ /**
* <p>Introspects the <code>Throwable</code> to obtain the cause.</p>
*
* <p>The method searches for methods with specific names that return a
@@ -712,7 +760,7 @@
while (frames.hasMoreTokens()) {
list.add(frames.nextToken());
}
- return (String[]) list.toArray(new String[list.size()]);
+ return toArray(list);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org