diff --git a/src/main/java/rx/exceptions/CompositeException.java b/src/main/java/rx/exceptions/CompositeException.java index b093c41437..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 = _cause; + 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)