Skip to content

Commit

Permalink
use bounded wildcards for errorHandler (fixes #5045) (#5049)
Browse files Browse the repository at this point in the history
* use bounded wildcards for errorHandler (fixes #5045)

* add test to ensure signature
  • Loading branch information
jschneider authored and akarnokd committed Feb 3, 2017
1 parent b5c0fb8 commit 471d590
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/main/java/io/reactivex/plugins/RxJavaPlugins.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*/
public final class RxJavaPlugins {
@Nullable
static volatile Consumer<Throwable> errorHandler;
static volatile Consumer<? super Throwable> errorHandler;

@Nullable
static volatile Function<Runnable, Runnable> onScheduleHandler;
Expand Down Expand Up @@ -197,7 +197,7 @@ public static Function<Scheduler, Scheduler> getComputationSchedulerHandler() {
* @return the hook consumer, may be null
*/
@Nullable
public static Consumer<Throwable> getErrorHandler() {
public static Consumer<? super Throwable> getErrorHandler() {
return errorHandler;
}

Expand Down Expand Up @@ -356,7 +356,7 @@ public static Scheduler onComputationScheduler(@NonNull Scheduler defaultSchedul
* @param error the error to report
*/
public static void onError(@NonNull Throwable error) {
Consumer<Throwable> f = errorHandler;
Consumer<? super Throwable> f = errorHandler;

if (error == null) {
error = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
Expand Down Expand Up @@ -497,7 +497,7 @@ public static void setComputationSchedulerHandler(@Nullable Function<Scheduler,
* Sets the specific hook function.
* @param handler the hook function to set, null allowed
*/
public static void setErrorHandler(@Nullable Consumer<Throwable> handler) {
public static void setErrorHandler(@Nullable Consumer<? super Throwable> handler) {
if (lockdown) {
throw new IllegalStateException("Plugins can't be changed anymore");
}
Expand Down
23 changes: 22 additions & 1 deletion src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,28 @@ public void uncaughtException(Thread t, Throwable e) {
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
/**
* Ensure setErrorHandler() accepts a consumer with "? super Throwable"
*/
@Test
public void onErrorWithSuper() throws Exception {
try {
Consumer<? super Throwable> errorHandler = new Consumer<Throwable>() {
@Override
public void accept(Throwable t) {
throw new TestException("Forced failure 2");
}
};
RxJavaPlugins.setErrorHandler(errorHandler);

Consumer<? super Throwable> errorHandler1 = RxJavaPlugins.getErrorHandler();
assertSame(errorHandler, errorHandler1);
} finally {
RxJavaPlugins.reset();
}
}

@SuppressWarnings({"rawtypes", "unchecked" })
@Test
public void clearIsPassthrough() {
try {
Expand Down

0 comments on commit 471d590

Please sign in to comment.