From 7efe1acafbed01949dabaa6c81418308a6e0d03c Mon Sep 17 00:00:00 2001 From: Prem Nirmal Date: Wed, 25 May 2016 15:52:29 -0400 Subject: [PATCH 1/2] cause should be the selected chain, not the original composite exception --- src/main/java/rx/exceptions/CompositeException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/rx/exceptions/CompositeException.java b/src/main/java/rx/exceptions/CompositeException.java index b093c41437..04038e3f16 100644 --- a/src/main/java/rx/exceptions/CompositeException.java +++ b/src/main/java/rx/exceptions/CompositeException.java @@ -155,7 +155,7 @@ public synchronized Throwable getCause() { chain = e; } } - cause = _cause; + cause = chain; } return cause; } From 3342511ca72ac2fa4814e791ad6a8f800ca0c73d Mon Sep 17 00:00:00 2001 From: Prem Nirmal Date: Wed, 25 May 2016 17:01:54 -0400 Subject: [PATCH 2/2] Cause should be the first throwable in the list of causes. Added test to check the cause --- .../java/rx/exceptions/CompositeException.java | 2 +- .../rx/exceptions/CompositeExceptionTest.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/rx/exceptions/CompositeException.java b/src/main/java/rx/exceptions/CompositeException.java index 04038e3f16..f4b77a02ed 100644 --- a/src/main/java/rx/exceptions/CompositeException.java +++ b/src/main/java/rx/exceptions/CompositeException.java @@ -155,7 +155,7 @@ public synchronized Throwable getCause() { chain = e; } } - cause = chain; + cause = !exceptions.isEmpty() ? exceptions.get(0) : _cause; } return cause; } diff --git a/src/test/java/rx/exceptions/CompositeExceptionTest.java b/src/test/java/rx/exceptions/CompositeExceptionTest.java index cba638e566..3ce38bba2d 100644 --- a/src/test/java/rx/exceptions/CompositeExceptionTest.java +++ b/src/test/java/rx/exceptions/CompositeExceptionTest.java @@ -61,6 +61,24 @@ public void testMultipleWithSameCause() { assertNotNull(getRootCause(ce)); System.err.println("----------------------------- print cause stacktrace"); ce.getCause().printStackTrace(); + + assertEquals(e1, ce.getCause()); + } + + @Test(timeout = 1000) + public void testCompositeExceptionCause() { + Throwable error = new Throwable("TheCause"); + CompositeException ce = new CompositeException(error); + + System.err.println("----------------------------- print composite stacktrace"); + ce.printStackTrace(); + + assertNoCircularReferences(ce); + assertNotNull(getRootCause(ce)); + System.err.println("----------------------------- print cause stacktrace"); + ce.getCause().printStackTrace(); + + assertEquals(error, ce.getCause()); } @Test(timeout = 1000)