From f6b1f8e4b67b6a413da9002006c30e49adfb59f2 Mon Sep 17 00:00:00 2001 From: Guillermo Calvo Date: Mon, 21 Jan 2019 10:50:49 +0900 Subject: [PATCH 1/2] Fix bug in CompositeException.getRootCause The original code use to be `if (root == null || root == e)`, but apparently after some refactoring it ended up as `if (root == null || cause == root)`, which I believe is a bug. This method should probably be `static` (that would have prevented the bug). --- src/main/java/io/reactivex/exceptions/CompositeException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/reactivex/exceptions/CompositeException.java b/src/main/java/io/reactivex/exceptions/CompositeException.java index 748b964cf7..4915688379 100644 --- a/src/main/java/io/reactivex/exceptions/CompositeException.java +++ b/src/main/java/io/reactivex/exceptions/CompositeException.java @@ -280,7 +280,7 @@ public int size() { */ /*private */Throwable getRootCause(Throwable e) { Throwable root = e.getCause(); - if (root == null || cause == root) { + if (root == null || e == root) { return e; } while (true) { From a7d97cbf3081c717c4567f3360e29d3c66496824 Mon Sep 17 00:00:00 2001 From: Guillermo Calvo Date: Mon, 21 Jan 2019 11:52:58 +0900 Subject: [PATCH 2/2] Update unit tests for CompositeException.getRootCause --- .../exceptions/CompositeExceptionTest.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java b/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java index 3625aa099a..2737b90712 100644 --- a/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java +++ b/src/test/java/io/reactivex/exceptions/CompositeExceptionTest.java @@ -364,7 +364,22 @@ public synchronized Throwable getCause() { } }; CompositeException ex = new CompositeException(throwable); - assertSame(ex, ex.getRootCause(ex)); + assertSame(ex0, ex.getRootCause(ex)); + } + + @Test + public void rootCauseSelf() { + Throwable throwable = new Throwable() { + + private static final long serialVersionUID = -4398003222998914415L; + + @Override + public synchronized Throwable getCause() { + return this; + } + }; + CompositeException tmp = new CompositeException(new TestException()); + assertSame(throwable, tmp.getRootCause(throwable)); } }