You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2009/03/15 03:10:47 UTC
svn commit: r754589 - in /commons/proper/lang/trunk/src:
java/org/apache/commons/lang/ java/org/apache/commons/lang/exception/
test/org/apache/commons/lang/ test/org/apache/commons/lang/exception/
Author: bayard
Date: Sun Mar 15 02:10:44 2009
New Revision: 754589
URL: http://svn.apache.org/viewvc?rev=754589&view=rev
Log:
Removing the Lang NestableException concept and instead relying on the JDK support. [LANG-492]. [LANG-491] notes the need to rethink ExceptionUtils and its test.
Removed:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/Nestable.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/NestableDelegate.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/NestableError.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/NestableException.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/NestableRuntimeException.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/AbstractNestableTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/NestableDelegateTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/NestableErrorTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/NestableExceptionTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/NestableRuntimeExceptionTest.java
Modified:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/NotImplementedException.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/SerializationException.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringEscapeUtils.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/UnhandledException.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/NotImplementedExceptionTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/UnhandledExceptionTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/ExceptionTestSuite.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/ExceptionUtilsTest.java
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/NotImplementedException.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/NotImplementedException.java?rev=754589&r1=754588&r2=754589&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/NotImplementedException.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/NotImplementedException.java Sun Mar 15 02:10:44 2009
@@ -19,9 +19,6 @@
import java.io.PrintStream;
import java.io.PrintWriter;
-import org.apache.commons.lang.exception.Nestable;
-import org.apache.commons.lang.exception.NestableDelegate;
-
/**
* <p>Thrown to indicate that a block of code has not been implemented.
* This exception supplements <code>UnsupportedOperationException</code>
@@ -29,9 +26,7 @@
*
* <p><code>NotImplementedException</code> represents the case where the
* author has yet to implement the logic at this point in the program.
- * This can act as an exception based TODO tag.
- * Because this logic might be within a catch block, this exception
- * suports exception chaining.</p>
+ * This can act as an exception based TODO tag. </p>
*
* <pre>
* public void foo() {
@@ -49,8 +44,7 @@
* @since 2.0
* @version $Id$
*/
-public class NotImplementedException
- extends UnsupportedOperationException implements Nestable {
+public class NotImplementedException extends UnsupportedOperationException {
private static final String DEFAULT_MESSAGE = "Code is not implemented";
@@ -61,17 +55,6 @@
*/
private static final long serialVersionUID = -6894122266938754088L;
- /**
- * The exception helper to delegate nested exception handling to.
- */
- private NestableDelegate delegate = new NestableDelegate(this);
-
- /**
- * Holds the reference to the exception or error that caused
- * this exception to be thrown.
- */
- private Throwable cause;
-
//-----------------------------------------------------------------------
/**
* Constructs a new <code>NotImplementedException</code> with default message.
@@ -100,8 +83,7 @@
* @since 2.1
*/
public NotImplementedException(Throwable cause) {
- super(DEFAULT_MESSAGE);
- this.cause = cause;
+ super(DEFAULT_MESSAGE, cause);
}
/**
@@ -113,8 +95,7 @@
* @since 2.1
*/
public NotImplementedException(String msg, Throwable cause) {
- super(msg == null ? DEFAULT_MESSAGE : msg);
- this.cause = cause;
+ super(msg == null ? DEFAULT_MESSAGE : msg, cause);
}
/**
@@ -127,174 +108,4 @@
super(clazz == null ? DEFAULT_MESSAGE : DEFAULT_MESSAGE + " in " + clazz);
}
- // -----------------------------------------------------------------------
- /**
- * Gets the root cause of this exception.
- * @return the root cause of this exception.
- *
- * @since 2.1
- */
- @Override
- public Throwable getCause() {
- return cause;
- }
-
- /**
- * Gets the combined the error message of this and any nested errors.
- *
- * @return the error message
- * @since 2.1
- */
- @Override
- public String getMessage() {
- if (super.getMessage() != null) {
- return super.getMessage();
- } else if (cause != null) {
- return cause.toString();
- } else {
- return null;
- }
- }
-
- /**
- * Returns the error message of the <code>Throwable</code> in the chain
- * of <code>Throwable</code>s at the specified index, numbered from 0.
- *
- * @param index the index of the <code>Throwable</code> in the chain
- * @return the error message, or null if the <code>Throwable</code> at the
- * specified index in the chain does not contain a message
- * @throws IndexOutOfBoundsException if the <code>index</code> argument is
- * negative or not less than the count of <code>Throwable</code>s in the chain
- * @since 2.1
- */
- public String getMessage(int index) {
- if (index == 0) {
- return super.getMessage();
- }
- return delegate.getMessage(index);
- }
-
- /**
- * Returns the error message of this and any nested <code>Throwable</code> objects.
- * Each throwable returns a message, a null string is included in the array if
- * there is no message for a particular <code>Throwable</code>.
- *
- * @return the error messages
- * @since 2.1
- */
- public String[] getMessages() {
- return delegate.getMessages();
- }
-
- /**
- * Returns the <code>Throwable</code> in the chain by index.
- *
- * @param index the index to retrieve
- * @return the <code>Throwable</code>
- * @throws IndexOutOfBoundsException if the <code>index</code> argument is
- * negative or not less than the count of <code>Throwable</code>s in the chain
- * @since 2.1
- */
- public Throwable getThrowable(int index) {
- return delegate.getThrowable(index);
- }
-
- /**
- * Returns the number of nested <code>Throwable</code>s represented by
- * this <code>Nestable</code>, including this <code>Nestable</code>.
- *
- * @return the throwable count
- * @since 2.1
- */
- public int getThrowableCount() {
- return delegate.getThrowableCount();
- }
-
- /**
- * Returns this <code>Nestable</code> and any nested <code>Throwable</code>s
- * in an array of <code>Throwable</code>s, one element for each
- * <code>Throwable</code>.
- *
- * @return the <code>Throwable</code>s
- * @since 2.1
- */
- public Throwable[] getThrowables() {
- return delegate.getThrowables();
- }
-
- /**
- * Returns the index of the first occurrence of the specified type.
- * If there is no match, <code>-1</code> is returned.
- *
- * @param type the type to search for
- * @return index of the first occurrence of the type in the chain, or -1 if
- * the type is not found
- * @since 2.1
- */
- public int indexOfThrowable(Class type) {
- return delegate.indexOfThrowable(type, 0);
- }
-
- /**
- * Returns the index of the first occurrence of the specified type starting
- * from the specified index. If there is no match, <code>-1</code> is returned.
- *
- * @param type the type to search for
- * @param fromIndex the index of the starting position in the chain to be searched
- * @return index of the first occurrence of the type in the chain, or -1 if
- * the type is not found
- * @throws IndexOutOfBoundsException if the <code>fromIndex</code> argument
- * is negative or not less than the count of <code>Throwable</code>s in the chain
- * @since 2.1
- */
- public int indexOfThrowable(Class type, int fromIndex) {
- return delegate.indexOfThrowable(type, fromIndex);
- }
-
- /**
- * Prints the stack trace of this exception.
- * Includes information from the exception, if any, which caused this exception.
- *
- * @since 2.1
- */
- @Override
- public void printStackTrace() {
- delegate.printStackTrace();
- }
-
- /**
- * Prints the stack trace of this exception to the specified stream.
- * Includes information from the exception, if any, which caused this exception.
- *
- * @param out the stream to write to
- * @since 2.1
- */
- @Override
- public void printStackTrace(PrintStream out) {
- delegate.printStackTrace(out);
- }
-
- /**
- * Prints the stack trace of this exception to the specified writer.
- * Includes information from the exception, if any, which caused this exception.
- *
- * @param out the writer to write to
- * @since 2.1
- */
- @Override
- public void printStackTrace(PrintWriter out) {
- delegate.printStackTrace(out);
- }
-
- /**
- * Prints the stack trace for this exception only (root cause not included)
- * using the specified writer.
- *
- * @param out the writer to write to
- * @since 2.1
- */
- public final void printPartialStackTrace(PrintWriter out) {
- super.printStackTrace(out);
- }
-
}
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/SerializationException.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/SerializationException.java?rev=754589&r1=754588&r2=754589&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/SerializationException.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/SerializationException.java Sun Mar 15 02:10:44 2009
@@ -16,8 +16,6 @@
*/
package org.apache.commons.lang;
-import org.apache.commons.lang.exception.NestableRuntimeException;
-
/**
* <p>Exception thrown when the Serialization process fails.</p>
*
@@ -27,7 +25,7 @@
* @since 1.0
* @version $Id$
*/
-public class SerializationException extends NestableRuntimeException {
+public class SerializationException extends RuntimeException {
/**
* Required for serialization support.
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringEscapeUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringEscapeUtils.java?rev=754589&r1=754588&r2=754589&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringEscapeUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringEscapeUtils.java Sun Mar 15 02:10:44 2009
@@ -21,8 +21,6 @@
import java.io.Writer;
import java.util.Locale;
-import org.apache.commons.lang.exception.NestableRuntimeException;
-
/**
* <p>Escapes and unescapes <code>String</code>s for
* Java, Java Script, HTML, XML, and SQL.</p>
@@ -331,7 +329,7 @@
inUnicode = false;
hadSlash = false;
} catch (NumberFormatException nfe) {
- throw new NestableRuntimeException("Unable to parse unicode value: " + unicode, nfe);
+ throw new UnhandledException("Unable to parse unicode value: " + unicode, nfe);
}
}
continue;
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/UnhandledException.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/UnhandledException.java?rev=754589&r1=754588&r2=754589&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/UnhandledException.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/UnhandledException.java Sun Mar 15 02:10:44 2009
@@ -16,8 +16,6 @@
*/
package org.apache.commons.lang;
-import org.apache.commons.lang.exception.NestableRuntimeException;
-
/**
* <p>Thrown when it is impossible or undesirable to consume or throw a checked exception.</p>
* This exception supplements the standard exception classes by providing a more
@@ -42,7 +40,7 @@
* @since 2.0
* @version $Id$
*/
-public class UnhandledException extends NestableRuntimeException {
+public class UnhandledException extends RuntimeException {
/**
* Required for serialization support.
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=754589&r1=754588&r2=754589&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 Sun Mar 15 02:10:44 2009
@@ -248,8 +248,7 @@
*
* <p>The method searches for methods with specific names that return a
* <code>Throwable</code> object. This will pick up most wrapping exceptions,
- * including those from JDK 1.4, and
- * {@link org.apache.commons.lang.exception.NestableException NestableException}.
+ * including those from JDK 1.4.
* The method names can be added to using {@link #addCauseMethodName(String)}.</p>
*
* <p>The default list searched for are:</p>
@@ -359,9 +358,7 @@
* @return the wrapped exception, or <code>null</code> if not found
*/
private static Throwable getCauseUsingWellKnownTypes(Throwable throwable) {
- if (throwable instanceof Nestable) {
- return ((Nestable) throwable).getCause();
- } else if (throwable instanceof SQLException) {
+ if (throwable instanceof SQLException) {
return ((SQLException) throwable).getNextException();
} else if (throwable instanceof InvocationTargetException) {
return ((InvocationTargetException) throwable).getTargetException();
@@ -457,9 +454,7 @@
return false;
}
- if (throwable instanceof Nestable) {
- return true;
- } else if (throwable instanceof SQLException) {
+ if (throwable instanceof SQLException) {
return true;
} else if (throwable instanceof InvocationTargetException) {
return true;
@@ -920,10 +915,6 @@
*
* <p>The end of line is determined by the value of {@link SystemUtils#LINE_SEPARATOR}.</p>
*
- * <p>Functionality shared between the
- * <code>getStackFrames(Throwable)</code> methods of this and the
- * {@link org.apache.commons.lang.exception.NestableDelegate} classes.</p>
- *
* @param stackTrace a stack trace String
* @return an array where each element is a line from the argument
*/
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/NotImplementedExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/NotImplementedExceptionTest.java?rev=754589&r1=754588&r2=754589&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/NotImplementedExceptionTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/NotImplementedExceptionTest.java Sun Mar 15 02:10:44 2009
@@ -27,8 +27,6 @@
import junit.framework.TestSuite;
import junit.textui.TestRunner;
-import org.apache.commons.lang.exception.NestableException;
-
/**
* JUnit tests.
*
@@ -112,59 +110,8 @@
assertEquals("Code is not implemented in class java.lang.String", ex.getMessage());
}
- public void testGetMessage_Indexed() throws Exception {
- if (SystemUtils.isJavaVersionAtLeast(1.4f)) {
- Exception ex1 = new Exception("nested 2");
- Constructor con = Exception.class.getConstructor(new Class[] {String.class, Throwable.class});
- Exception ex2 = (Exception) con.newInstance(new Object[] {"nested 1", ex1});
- NotImplementedException ex = new NotImplementedException(ex2);
- assertEquals("Code is not implemented", ex.getMessage());
- assertEquals("Code is not implemented", ex.getMessage(0));
- assertEquals("nested 1", ex.getMessage(1));
- assertEquals("nested 2", ex.getMessage(2));
-
- String[] messages = ex.getMessages();
- assertEquals(3, messages.length);
- assertEquals("Code is not implemented", messages[0]);
- assertEquals("nested 1", messages[1]);
- assertEquals("nested 2", messages[2]);
- }
- }
-
- public void testGetThrowable() {
- NotImplementedException ex = new NotImplementedException(new NestableException("nested 1", new NestableException("nested 2")));
-
- assertEquals(3, ex.getThrowableCount());
-
- assertEquals(NotImplementedException.class, ex.getThrowable(0).getClass());
- assertEquals("Code is not implemented", ex.getThrowable(0).getMessage());
- assertEquals(NestableException.class, ex.getThrowable(1).getClass());
- assertEquals("nested 1", ex.getThrowable(1).getMessage());
- assertEquals(NestableException.class, ex.getThrowable(2).getClass());
- assertEquals("nested 2", ex.getThrowable(2).getMessage());
-
- assertEquals(3, ex.getThrowables().length);
- assertEquals(NotImplementedException.class, ex.getThrowables()[0].getClass());
- assertEquals("Code is not implemented", ex.getThrowables()[0].getMessage());
- assertEquals(NestableException.class, ex.getThrowables()[1].getClass());
- assertEquals("nested 1", ex.getThrowables()[1].getMessage());
- assertEquals(NestableException.class, ex.getThrowables()[2].getClass());
- assertEquals("nested 2", ex.getThrowables()[2].getMessage());
- }
-
- public void testIndexOfThrowable() {
- NotImplementedException ex = new NotImplementedException(new NestableException("nested 1", new NestableException("nested 2")));
- assertEquals(0, ex.indexOfThrowable(NotImplementedException.class));
- assertEquals(1, ex.indexOfThrowable(NestableException.class));
- }
-
- public void testIndexOfThrowable_Index() {
- NotImplementedException ex = new NotImplementedException(new NestableException("nested 1", new NestableException("nested 2")));
- assertEquals(1, ex.indexOfThrowable(NestableException.class, 1));
- }
-
public void testPrintStackTrace() {
- NotImplementedException ex = new NotImplementedException(new NestableException("nested 1", new NestableException("nested 2")));
+ NotImplementedException ex = new NotImplementedException(new Exception("nested 1", new RuntimeException("nested 2")));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream errStream = System.err;
@@ -175,7 +122,7 @@
}
public void testPrintStackTrace_Stream() {
- NotImplementedException ex = new NotImplementedException(new NestableException("nested 1", new NestableException("nested 2")));
+ NotImplementedException ex = new NotImplementedException(new Exception("nested 1", new RuntimeException("nested 2")));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
ex.printStackTrace(ps);
@@ -183,18 +130,11 @@
}
public void testPrintStackTrace_Writer() {
- NotImplementedException ex = new NotImplementedException(new NestableException("nested 1", new NestableException("nested 2")));
+ NotImplementedException ex = new NotImplementedException(new Exception("nested 1", new RuntimeException("nested 2")));
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
ex.printStackTrace(writer);
assertTrue(stringWriter.toString().length() > 0);
}
- public void testPrintPartialStackTrace_Writer() {
- NotImplementedException ex = new NotImplementedException(new NestableException("nested 1", new NestableException("nested 2")));
- StringWriter stringWriter = new StringWriter();
- PrintWriter writer = new PrintWriter(stringWriter);
- ex.printPartialStackTrace(writer);
- assertTrue(stringWriter.toString().length() > 0);
- }
}
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/UnhandledExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/UnhandledExceptionTest.java?rev=754589&r1=754588&r2=754589&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/UnhandledExceptionTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/UnhandledExceptionTest.java Sun Mar 15 02:10:44 2009
@@ -21,8 +21,6 @@
import junit.framework.TestSuite;
import junit.textui.TestRunner;
-import org.apache.commons.lang.exception.Nestable;
-
/**
* JUnit tests.
*
@@ -59,14 +57,14 @@
public void testGetCause() {
final Throwable t = new NullPointerException();
- final Nestable n = new UnhandledException(t);
+ final Throwable n = new UnhandledException(t);
assertEquals(t, n.getCause());
}
public void testGetCauseAndGetMessage() {
final Throwable t = new NullPointerException();
final String msg = "nullArg";
- final Nestable n = new UnhandledException(msg, t);
+ final Throwable n = new UnhandledException(msg, t);
assertEquals(t, n.getCause());
assertEquals(msg, n.getMessage());
}
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/ExceptionTestSuite.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/ExceptionTestSuite.java?rev=754589&r1=754588&r2=754589&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/ExceptionTestSuite.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/ExceptionTestSuite.java Sun Mar 15 02:10:44 2009
@@ -47,10 +47,6 @@
public static Test suite()
{
TestSuite suite = new TestSuite();
- suite.addTest(NestableDelegateTest.suite());
- suite.addTest(NestableErrorTest.suite());
- suite.addTest(NestableExceptionTest.suite());
- suite.addTest(NestableRuntimeExceptionTest.suite());
suite.addTest(ExceptionUtilsTest.suite());
return suite;
}
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/ExceptionUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/ExceptionUtilsTest.java?rev=754589&r1=754588&r2=754589&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/ExceptionUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/exception/ExceptionUtilsTest.java Sun Mar 15 02:10:44 2009
@@ -173,11 +173,6 @@
assertSame(null, ExceptionUtils.getCause(null, null));
assertSame(null, ExceptionUtils.getCause(null, new String[0]));
- // match because known type
- assertSame(withoutCause, ExceptionUtils.getCause(nested, null));
- assertSame(withoutCause, ExceptionUtils.getCause(nested, new String[0]));
- assertSame(withoutCause, ExceptionUtils.getCause(nested, new String[] {"getCause"}));
-
// not known type, so match on supplied method names
assertSame(nested, ExceptionUtils.getCause(withCause, null)); // default names
assertSame(null, ExceptionUtils.getCause(withCause, new String[0]));
@@ -601,4 +596,15 @@
}
}
+ // Temporary classes to allow the nested exception code to be removed
+ // prior to a rewrite of this test class.
+ private static class NestableRuntimeException extends RuntimeException {
+ public NestableRuntimeException() { super(); }
+ public NestableRuntimeException(Throwable t) { super(t); }
+ }
+ private static class NestableException extends Exception {
+ public NestableException() { super(); }
+ public NestableException(Throwable t) { super(t); }
+ }
+
}