From 324d26687919a5e1fc3de44f2998dce700e2149a Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Thu, 6 Nov 2008 12:21:37 +0000 Subject: QPID-1434 : Changed rethrow() name based on feedback from Rob git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@711848 13f79535-47bb-0310-9956-ffa450edef68 --- .../qpid/client/protocol/AMQProtocolHandler.java | 2 +- .../main/java/org/apache/qpid/AMQException.java | 7 ++- .../java/org/apache/qpid/AMQExceptionTest.java | 60 +++++++--------------- 3 files changed, 23 insertions(+), 46 deletions(-) (limited to 'java') diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java index bf32b4df1f..20beec5cc4 100644 --- a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java +++ b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java @@ -673,7 +673,7 @@ public class AMQProtocolHandler extends IoHandlerAdapter { AMQException amqe = (AMQException) e; - amqe.rethrow(); + throw amqe.cloneForCurrentThread(); } else { diff --git a/java/common/src/main/java/org/apache/qpid/AMQException.java b/java/common/src/main/java/org/apache/qpid/AMQException.java index 1cfd7e3134..be335c5dba 100644 --- a/java/common/src/main/java/org/apache/qpid/AMQException.java +++ b/java/common/src/main/java/org/apache/qpid/AMQException.java @@ -98,10 +98,9 @@ public class AMQException extends Exception * {AMQConstant.class, String.class, Throwable.class} * * Individual subclasses may override as requried to create a new instance. - * - * @throws AMQException + * */ - public void rethrow() throws AMQException + public AMQException cloneForCurrentThread() { Class amqeClass = this.getClass(); Class[] paramClasses = {AMQConstant.class, String.class, Throwable.class}; @@ -118,6 +117,6 @@ public class AMQException extends Exception newAMQE = new AMQException(getErrorCode(), getMessage(), this); } - throw newAMQE; + return newAMQE; } } diff --git a/java/common/src/test/java/org/apache/qpid/AMQExceptionTest.java b/java/common/src/test/java/org/apache/qpid/AMQExceptionTest.java index 853dc85592..ef6cd41492 100644 --- a/java/common/src/test/java/org/apache/qpid/AMQExceptionTest.java +++ b/java/common/src/test/java/org/apache/qpid/AMQExceptionTest.java @@ -42,14 +42,10 @@ public class AMQExceptionTest extends TestCase { AMQException test = new AMQException(AMQConstant.ACCESS_REFUSED, "refused", new RuntimeException()); - try - { - reThrowException(test); - } - catch (AMQException e) - { - assertEquals("Exception not of correct class", AMQException.class, e.getClass()); - } + AMQException e = reThrowException(test); + + assertEquals("Exception not of correct class", AMQException.class, e.getClass()); + } /** @@ -60,14 +56,9 @@ public class AMQExceptionTest extends TestCase AMQFrameDecodingException test = new AMQFrameDecodingException(AMQConstant.INTERNAL_ERROR, "Error", new Exception()); - try - { - reThrowException(test); - } - catch (AMQException e) - { - assertEquals("Exception not of correct class", AMQFrameDecodingException.class, e.getClass()); - } + AMQException e = reThrowException(test); + + assertEquals("Exception not of correct class", AMQFrameDecodingException.class, e.getClass()); } /** @@ -77,14 +68,10 @@ public class AMQExceptionTest extends TestCase public void testRethrowAMQESubclassNoConstructor() { AMQExceptionSubclass test = new AMQExceptionSubclass("Invalid Argument Exception"); - try - { - reThrowException(test); - } - catch (AMQException e) - { - assertEquals("Exception not of correct class", AMQException.class, e.getClass()); - } + + AMQException e = reThrowException(test); + + assertEquals("Exception not of correct class", AMQException.class, e.getClass()); } /** @@ -92,25 +79,16 @@ public class AMQExceptionTest extends TestCase * @param test Exception to rethrow * @throws AMQException the rethrown exception */ - private void reThrowException(AMQException test) throws AMQException + private AMQException reThrowException(AMQException test) { - try - { - test.rethrow(); - } - catch (AMQException amqe) - { - assertEquals("Error code does not match.", test.getErrorCode(), amqe.getErrorCode()); - assertTrue("Exception message does not start as expected.", amqe.getMessage().startsWith(test.getMessage())); - assertEquals("Test Exception is not set as the cause", test, amqe.getCause()); - assertEquals("Cause is not correct", test.getCause(), amqe.getCause().getCause()); - throw amqe; - } - catch (Throwable e) - { - fail("Throwable recieved when AMQException expected:" + e); - } + AMQException amqe = test.cloneForCurrentThread(); + + assertEquals("Error code does not match.", test.getErrorCode(), amqe.getErrorCode()); + assertTrue("Exception message does not start as expected.", amqe.getMessage().startsWith(test.getMessage())); + assertEquals("Test Exception is not set as the cause", test, amqe.getCause()); + assertEquals("Cause is not correct", test.getCause(), amqe.getCause().getCause()); + return amqe; } /** -- cgit v1.2.1