From a22cce7c5e0da403849d265753c5dc1f889fc109 Mon Sep 17 00:00:00 2001 From: zsxwing Date: Tue, 2 Jun 2015 17:12:27 +0800 Subject: [PATCH 1/2] Replace the Java 7 AssertionError(message, cause) with RuntimeException --- src/main/java/rx/observers/TestSubscriber.java | 18 ++++++++++++------ src/main/java/rx/subjects/ReplaySubject.java | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/rx/observers/TestSubscriber.java b/src/main/java/rx/observers/TestSubscriber.java index bdb69663a3..c35475cfa9 100644 --- a/src/main/java/rx/observers/TestSubscriber.java +++ b/src/main/java/rx/observers/TestSubscriber.java @@ -356,10 +356,12 @@ public void assertError(Class clazz) { throw new AssertionError("No errors"); } else if (err.size() > 1) { - throw new AssertionError("Multiple errors: " + err.size(), new CompositeException(err)); + // can't use AssertionError because (message, cause) doesn't exist until Java 7 + throw new RuntimeException("Multiple errors: " + err.size(), new CompositeException(err)); } else if (!clazz.isInstance(err.get(0))) { - throw new AssertionError("Exceptions differ; expected: " + clazz + ", actual: " + err.get(0), err.get(0)); + // can't use AssertionError because (message, cause) doesn't exist until Java 7 + throw new RuntimeException("Exceptions differ; expected: " + clazz + ", actual: " + err.get(0), err.get(0)); } } @@ -378,10 +380,12 @@ public void assertError(Throwable throwable) { throw new AssertionError("No errors"); } else if (err.size() > 1) { - throw new AssertionError("Multiple errors: " + err.size(), new CompositeException(err)); + // can't use AssertionError because (message, cause) doesn't exist until Java 7 + throw new RuntimeException("Multiple errors: " + err.size(), new CompositeException(err)); } else if (!throwable.equals(err.get(0))) { - throw new AssertionError("Exceptions differ; expected: " + throwable + ", actual: " + err.get(0), err.get(0)); + // can't use AssertionError because (message, cause) doesn't exist until Java 7 + throw new RuntimeException("Exceptions differ; expected: " + throwable + ", actual: " + err.get(0), err.get(0)); } } @@ -400,9 +404,11 @@ public void assertNoTerminalEvent() { throw new AssertionError("Found " + err.size() + " errors and " + s + " completion events instead of none"); } else if (err.size() == 1) { - throw new AssertionError("Found " + err.size() + " errors and " + s + " completion events instead of none", err.get(0)); + // can't use AssertionError because (message, cause) doesn't exist until Java 7 + throw new RuntimeException("Found " + err.size() + " errors and " + s + " completion events instead of none", err.get(0)); } else { - throw new AssertionError("Found " + err.size() + " errors and " + s + " completion events instead of none", new CompositeException(err)); + // can't use AssertionError because (message, cause) doesn't exist until Java 7 + throw new RuntimeException("Found " + err.size() + " errors and " + s + " completion events instead of none", new CompositeException(err)); } } } diff --git a/src/main/java/rx/subjects/ReplaySubject.java b/src/main/java/rx/subjects/ReplaySubject.java index 418a7d7f4e..c3779dac2d 100644 --- a/src/main/java/rx/subjects/ReplaySubject.java +++ b/src/main/java/rx/subjects/ReplaySubject.java @@ -114,7 +114,7 @@ public void call(SubjectObserver o) { boolean skipFinal = false; try { for (;;) { - int idx = o.index(); + int idx = o.index(); int sidx = state.index; if (idx != sidx) { Integer j = state.replayObserverFromIndex(idx, o); From 596ecd2a53f119086d406da21f0190a257437743 Mon Sep 17 00:00:00 2001 From: zsxwing Date: Tue, 2 Jun 2015 20:10:21 +0800 Subject: [PATCH 2/2] Use initCause to initialize AssertionError --- .../java/rx/observers/TestSubscriber.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/rx/observers/TestSubscriber.java b/src/main/java/rx/observers/TestSubscriber.java index c35475cfa9..284002d452 100644 --- a/src/main/java/rx/observers/TestSubscriber.java +++ b/src/main/java/rx/observers/TestSubscriber.java @@ -356,12 +356,14 @@ public void assertError(Class clazz) { throw new AssertionError("No errors"); } else if (err.size() > 1) { - // can't use AssertionError because (message, cause) doesn't exist until Java 7 - throw new RuntimeException("Multiple errors: " + err.size(), new CompositeException(err)); + AssertionError ae = new AssertionError("Multiple errors: " + err.size()); + ae.initCause(new CompositeException(err)); + throw ae; } else if (!clazz.isInstance(err.get(0))) { - // can't use AssertionError because (message, cause) doesn't exist until Java 7 - throw new RuntimeException("Exceptions differ; expected: " + clazz + ", actual: " + err.get(0), err.get(0)); + AssertionError ae = new AssertionError("Exceptions differ; expected: " + clazz + ", actual: " + err.get(0)); + ae.initCause(err.get(0)); + throw ae; } } @@ -380,12 +382,14 @@ public void assertError(Throwable throwable) { throw new AssertionError("No errors"); } else if (err.size() > 1) { - // can't use AssertionError because (message, cause) doesn't exist until Java 7 - throw new RuntimeException("Multiple errors: " + err.size(), new CompositeException(err)); + AssertionError ae = new AssertionError("Multiple errors: " + err.size()); + ae.initCause(new CompositeException(err)); + throw ae; } else if (!throwable.equals(err.get(0))) { - // can't use AssertionError because (message, cause) doesn't exist until Java 7 - throw new RuntimeException("Exceptions differ; expected: " + throwable + ", actual: " + err.get(0), err.get(0)); + AssertionError ae = new AssertionError("Exceptions differ; expected: " + throwable + ", actual: " + err.get(0)); + ae.initCause(err.get(0)); + throw ae; } } @@ -404,11 +408,13 @@ public void assertNoTerminalEvent() { throw new AssertionError("Found " + err.size() + " errors and " + s + " completion events instead of none"); } else if (err.size() == 1) { - // can't use AssertionError because (message, cause) doesn't exist until Java 7 - throw new RuntimeException("Found " + err.size() + " errors and " + s + " completion events instead of none", err.get(0)); + AssertionError ae = new AssertionError("Found " + err.size() + " errors and " + s + " completion events instead of none"); + ae.initCause(err.get(0)); + throw ae; } else { - // can't use AssertionError because (message, cause) doesn't exist until Java 7 - throw new RuntimeException("Found " + err.size() + " errors and " + s + " completion events instead of none", new CompositeException(err)); + AssertionError ae = new AssertionError("Found " + err.size() + " errors and " + s + " completion events instead of none"); + ae.initCause(new CompositeException(err)); + throw ae; } } }