Skip to content

Commit ca2568c

Browse files
committed
Remove ThrowableWrapper, fix attempt at flaky tests
1 parent f74b39c commit ca2568c

10 files changed

Lines changed: 52 additions & 147 deletions

File tree

src/main/java/io/reactivex/rxjava4/core/CompletionStageDisposable.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
import java.util.function.Consumer;
2222

2323
import io.reactivex.rxjava4.annotations.NonNull;
24-
import io.reactivex.rxjava4.disposables.*;
25-
import io.reactivex.rxjava4.exceptions.ThrowableWrapper;
26-
import io.reactivex.rxjava4.internal.util.*;
24+
import io.reactivex.rxjava4.disposables.Disposable;
25+
import io.reactivex.rxjava4.internal.util.ExceptionHelper;
2726
import io.reactivex.rxjava4.plugins.RxJavaPlugins;
2827

2928
/**
@@ -88,14 +87,14 @@ public CompletionStageDisposable(@NonNull CompletionStage<T> stage, @NonNull Dis
8887
* <p>
8988
* Rethrows any original unchecked exceptions as is.
9089
* @throws CancellationException if the computation was cancelled
91-
* @throws ThrowableWrapper if the original exception was a checked exception
90+
* @throws CompletionException if the original exception was a checked exception
9291
*/
9392
public void await() {
9493
state.lazySet(true);
9594
try {
9695
stage.toCompletableFuture().join();
9796
} catch (CompletionException ce) {
98-
throw ExceptionHelper.wrapOrThrow(ce.getCause());
97+
throw ExceptionHelper.unwrapOrThrow(ce);
9998
}
10099
}
101100

src/main/java/io/reactivex/rxjava4/exceptions/Exceptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.reactivex.rxjava4.exceptions;
1515

16+
import java.util.concurrent.CompletionException;
17+
1618
import io.reactivex.rxjava4.annotations.NonNull;
1719
import io.reactivex.rxjava4.internal.util.ExceptionHelper;
1820

@@ -28,7 +30,7 @@ private Exceptions() {
2830
}
2931
/**
3032
* Convenience method to throw a {@code RuntimeException} and {@code Error} directly
31-
* or wrap any other exception type into a {@link ThrowableWrapper}.
33+
* or wrap any other exception type into a {@link CompletionException}.
3234
* @param t the exception to throw directly or wrapped
3335
* @return because {@code propagate} itself throws an exception or error, this is a sort of phantom return
3436
* value; {@code propagate} does not actually return anything

src/main/java/io/reactivex/rxjava4/exceptions/ThrowableWrapper.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/main/java/io/reactivex/rxjava4/internal/operators/streamable/StreamableTimer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public void run() {
7474
}
7575

7676
void interrupedSleep(InterruptedException ex) {
77-
waiter.completeExceptionally(ex);
77+
if (!isDisposed()) {
78+
waiter.completeExceptionally(ex);
79+
}
7880
}
7981

8082
@Override

src/main/java/io/reactivex/rxjava4/internal/util/ExceptionHelper.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import java.util.concurrent.*;
1919
import java.util.concurrent.atomic.AtomicReference;
2020

21-
import io.reactivex.rxjava4.annotations.Nullable;
22-
import io.reactivex.rxjava4.exceptions.*;
21+
import io.reactivex.rxjava4.annotations.*;
22+
import io.reactivex.rxjava4.exceptions.CompositeException;
2323

2424
/**
2525
* Terminal atomics for Throwable containers.
@@ -33,19 +33,39 @@ private ExceptionHelper() {
3333

3434
/**
3535
* If the provided Throwable is an Error this method
36-
* throws it, otherwise returns a RuntimeException wrapping the error
36+
* throws it, otherwise returns a CompletionException wrapping the error
3737
* if that error is a checked exception.
3838
* @param error the error to wrap or throw
3939
* @return the (wrapped) error
4040
*/
41-
public static RuntimeException wrapOrThrow(Throwable error) {
41+
@NonNull
42+
public static RuntimeException wrapOrThrow(@NonNull Throwable error) {
4243
if (error instanceof Error err) {
4344
throw err;
4445
}
4546
if (error instanceof RuntimeException rte) {
4647
return rte;
4748
}
48-
return new ThrowableWrapper(error);
49+
return new CompletionException("You forgot to unwrap me!", error);
50+
}
51+
/**
52+
* Unwraps a {@link CompletionException} and rethrows its {@link Error}
53+
* or {@link RuntimeException} inside it, or returns it as is if
54+
* the {@code CompletionException} holds a checked exception.
55+
* @param error the error to unwrap and rethrow its cause if possible
56+
* @return the {@code error} if it has a checked exception cause
57+
* @since 4.0.0
58+
*/
59+
@NonNull
60+
public static RuntimeException unwrapOrThrow(@NonNull CompletionException error) {
61+
var cause = error.getCause();
62+
if (cause instanceof Error err) {
63+
throw err;
64+
}
65+
if (cause instanceof RuntimeException rte) {
66+
return rte;
67+
}
68+
return error;
4969
}
5070

5171
/**
@@ -184,19 +204,19 @@ public static <T> T nullCheck(T value, String prefix) {
184204
}
185205

186206
/**
187-
* Unwraps both throwables if they are wrapped into a {@link CompletionException} or
188-
* {@link ThrowableWrapper}, then if both are present, add {@code b} as suppressed to {@code a}
207+
* Unwraps both throwables if they are wrapped into a {@link CompletionException},
208+
* then if both are present, add {@code b} as suppressed to {@code a}
189209
* and return a; return b otherwise
190210
* @param main the first throwable
191211
* @param secondary the second throwable
192212
* @return the unwrapped and combined throwable or null if both where
193213
*/
194214
@Nullable
195215
public static Throwable unwrapAndCombine(@Nullable Throwable main, @Nullable Throwable secondary) {
196-
if (main instanceof CompletionException || main instanceof ThrowableWrapper) {
216+
if (main instanceof CompletionException) {
197217
main = main.getCause();
198218
}
199-
if (secondary instanceof CompletionException || secondary instanceof ThrowableWrapper) {
219+
if (secondary instanceof CompletionException) {
200220
secondary = secondary.getCause();
201221
}
202222
if (main != null && secondary != null && main != secondary) {
@@ -209,12 +229,12 @@ public static Throwable unwrapAndCombine(@Nullable Throwable main, @Nullable Thr
209229
}
210230

211231
/**
212-
* Unwraps the given {@link CompletionException} or {@link ThrowableWrapper}
232+
* Unwraps the given {@link CompletionException}.
213233
* @param t the possible throwable to unwrap
214234
* @return the unwrapped Throwable
215235
*/
216236
public static Throwable unwrap(@Nullable Throwable t) {
217-
if (t instanceof CompletionException || t instanceof ThrowableWrapper) {
237+
if (t instanceof CompletionException) {
218238
t = t.getCause();
219239
}
220240
return t;

src/main/java/io/reactivex/rxjava4/internal/virtual/FlowableVirtualCreateExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import io.reactivex.rxjava4.core.*;
2323
import io.reactivex.rxjava4.disposables.*;
2424
import io.reactivex.rxjava4.exceptions.*;
25-
import io.reactivex.rxjava4.internal.util.BackpressureHelper;
25+
import io.reactivex.rxjava4.internal.util.*;
2626

2727
/**
2828
* Runs a generator callback on a virtual thread backed by a Worker of the given scheduler
@@ -105,7 +105,7 @@ public Void call() {
105105
} catch (Throwable ex) {
106106
Exceptions.throwIfFatal(ex);
107107
if (ex != STOP && !cancelled) {
108-
downstream.onError(ThrowableWrapper.unwrap(ex));
108+
downstream.onError(ExceptionHelper.unwrap(ex));
109109
}
110110
return null;
111111
}

src/main/java/io/reactivex/rxjava4/internal/virtual/FlowableVirtualTransformExecutor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import io.reactivex.rxjava4.core.*;
2323
import io.reactivex.rxjava4.core.Scheduler.Worker;
2424
import io.reactivex.rxjava4.disposables.*;
25-
import io.reactivex.rxjava4.exceptions.*;
26-
import io.reactivex.rxjava4.internal.util.BackpressureHelper;
25+
import io.reactivex.rxjava4.exceptions.Exceptions;
26+
import io.reactivex.rxjava4.internal.util.*;
2727
import io.reactivex.rxjava4.operators.SpscArrayQueue;
2828

2929
public final class FlowableVirtualTransformExecutor<T, R> extends Flowable<R> {
@@ -206,7 +206,7 @@ public Void call() {
206206
if (d && empty) {
207207
var ex = error;
208208
if (ex != null) {
209-
downstream.onError(ThrowableWrapper.unwrap(ex));
209+
downstream.onError(ExceptionHelper.unwrap(ex));
210210
} else {
211211
downstream.onComplete();
212212
}
@@ -234,7 +234,7 @@ public Void call() {
234234
Exceptions.throwIfFatal(ex);
235235
if (ex != STOP && !cancelled) {
236236
upstream.cancel();
237-
downstream.onError(ThrowableWrapper.unwrap(ex));
237+
downstream.onError(ExceptionHelper.unwrap(ex));
238238
}
239239
return null;
240240
}

src/test/java/io/reactivex/rxjava4/exceptions/ThrowableWrapperTest.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/test/java/io/reactivex/rxjava4/internal/operators/streamable/StreamableForEachTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class StreamableForEachTest extends StreamableBaseTest {
2929

3030
@Test
3131
public void forEachCheckedCrash() {
32-
var ex = assertThrows(ThrowableWrapper.class, () -> {
32+
var ex = assertThrows(CompletionException.class, () -> {
3333
Streamable.just(1)
3434
.forEach(_ -> {
3535
throw new Exception("test");
@@ -58,7 +58,7 @@ public void forEachUncheckedCrash() {
5858
@Test
5959
public void forEachExecCheckedCrash() throws Throwable {
6060
withCachedExecutor(exec -> {
61-
var ex = assertThrows(ThrowableWrapper.class, () -> {
61+
var ex = assertThrows(CompletionException.class, () -> {
6262
Streamable.just(1)
6363
.forEach(_ -> {
6464
throw new Exception("test");
@@ -90,7 +90,7 @@ public void forEachExecUncheckedCrash() throws Throwable {
9090
@Test
9191
public void forEachBiCheckedCrash() throws Throwable {
9292
withVirtual(exec -> {
93-
var ex = assertThrows(ThrowableWrapper.class, () -> {
93+
var ex = assertThrows(CompletionException.class, () -> {
9494
Streamable.just(1)
9595
.forEach((_, _) -> {
9696
throw new Exception("test");

src/test/java/io/reactivex/rxjava4/internal/util/ExceptionHelperTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ public void unwrapAndCombine6() {
9191
@Test
9292
public void unwrapAndCombine7() {
9393
var te = new TestException();
94-
assertSame(te, ExceptionHelper.unwrapAndCombine(new ThrowableWrapper(te), null));
94+
assertSame(te, ExceptionHelper.unwrapAndCombine(new CompletionException(te), null));
9595
}
9696

9797
@Test
9898
public void unwrapAndCombine8() {
9999
var te = new TestException();
100-
assertSame(te, ExceptionHelper.unwrapAndCombine(null, new ThrowableWrapper(te)));
100+
assertSame(te, ExceptionHelper.unwrapAndCombine(null, new CompletionException(te)));
101101
}
102102
}

0 commit comments

Comments
 (0)