Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the Java 7 AssertionError(message, cause) with initCause #3000

Merged
merged 2 commits into from
Jun 2, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/main/java/rx/observers/TestSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@ public void assertError(Class<? extends Throwable> 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use initCause()

AssertionError ae = new AssertionError(...);
ae.initCause(...)
throw ae;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Updated. I have not updated assertNoErrors because changing from RuntimeException to AssertionError is a breaking change.

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));
}
}

Expand All @@ -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));
}
}

Expand All @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/rx/subjects/ReplaySubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void call(SubjectObserver<T> o) {
boolean skipFinal = false;
try {
for (;;) {
int idx = o.index();
int idx = o.<Integer>index();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java 6 compiler is not smart enough to infer Integer.

int sidx = state.index;
if (idx != sidx) {
Integer j = state.replayObserverFromIndex(idx, o);
Expand Down