Skip to content

Commit 2edba23

Browse files
authored
3.x: Standardize MissingBackpressureException message, introduce QueueOverflowException (#7459)
* 3.x: Standardize MissingBackpressureException messages * Use the correct message. * Fix tests * Add QueueOverflowException, fix tests * Update CompletableConcatTest.java
1 parent ef51a90 commit 2edba23

File tree

61 files changed

+164
-94
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+164
-94
lines changed

src/main/java/io/reactivex/rxjava3/exceptions/MissingBackpressureException.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ public final class MissingBackpressureException extends RuntimeException {
2020

2121
private static final long serialVersionUID = 8517344746016032542L;
2222

23+
/**
24+
* The default error message.
25+
* <p>
26+
* This can happen if the downstream doesn't call {@link org.reactivestreams.Subscription#request(long)}
27+
* in time or at all.
28+
* @since 3.1.6
29+
*/
30+
public static final String DEFAULT_MESSAGE = "Could not emit value due to lack of requests";
31+
2332
/**
2433
* Constructs a MissingBackpressureException without message or cause.
2534
*/
@@ -35,4 +44,13 @@ public MissingBackpressureException(String message) {
3544
super(message);
3645
}
3746

47+
/**
48+
* Constructs a new {@code MissingBackpressureException} with the
49+
* default message {@value #DEFAULT_MESSAGE}.
50+
* @return the new {@code MissingBackpressureException} instance.
51+
* @since 3.1.6
52+
*/
53+
public static MissingBackpressureException createDefault() {
54+
return new MissingBackpressureException(DEFAULT_MESSAGE);
55+
}
3856
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2016-present, RxJava Contributors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
* compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11+
* the License for the specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package io.reactivex.rxjava3.exceptions;
15+
16+
/**
17+
* Indicates an overflow happened because the upstream disregarded backpressure completely or
18+
* {@link org.reactivestreams.Subscriber#onNext(Object)} was called concurrently from multiple threads
19+
* without synchronization. Rarely, it is an indication of bugs inside an operator.
20+
* @since 3.1.6
21+
*/
22+
public final class QueueOverflowException extends RuntimeException {
23+
24+
private static final long serialVersionUID = 8517344746016032542L;
25+
26+
/**
27+
* The message for queue overflows.
28+
* <p>
29+
* This can happen if the upstream disregards backpressure completely or calls
30+
* {@link org.reactivestreams.Subscriber#onNext(Object)} concurrently from multiple threads
31+
* without synchronization. Rarely, it is an indication of bugs inside an operator.
32+
*/
33+
private static final String DEFAULT_MESSAGE = "Queue overflow due to illegal concurrent onNext calls or a bug in an operator";
34+
35+
/**
36+
* Constructs a QueueOverflowException with the default message.
37+
*/
38+
public QueueOverflowException() {
39+
this(DEFAULT_MESSAGE);
40+
}
41+
42+
/**
43+
* Constructs a QueueOverflowException with the given message but no cause.
44+
* @param message the error message
45+
*/
46+
public QueueOverflowException(String message) {
47+
super(message);
48+
}
49+
}

src/main/java/io/reactivex/rxjava3/internal/jdk8/FlowableFlatMapStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public void onNext(T t) {
174174
if (sourceMode != QueueFuseable.ASYNC) {
175175
if (!queue.offer(t)) {
176176
upstream.cancel();
177-
onError(new MissingBackpressureException("Queue full?!"));
177+
onError(new QueueOverflowException());
178178
return;
179179
}
180180
}

src/main/java/io/reactivex/rxjava3/internal/operators/completable/CompletableConcat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void onSubscribe(Subscription s) {
120120
public void onNext(CompletableSource t) {
121121
if (sourceFused == QueueSubscription.NONE) {
122122
if (!queue.offer(t)) {
123-
onError(new MissingBackpressureException());
123+
onError(new QueueOverflowException());
124124
return;
125125
}
126126
}

src/main/java/io/reactivex/rxjava3/internal/operators/flowable/BlockingFlowableIterable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void onNext(T t) {
140140
if (!queue.offer(t)) {
141141
SubscriptionHelper.cancel(this);
142142

143-
onError(new MissingBackpressureException("Queue full?!"));
143+
onError(new QueueOverflowException());
144144
} else {
145145
signalConsumer();
146146
}

src/main/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableConcatMap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.reactivestreams.*;
2020

2121
import io.reactivex.rxjava3.core.*;
22-
import io.reactivex.rxjava3.exceptions.Exceptions;
22+
import io.reactivex.rxjava3.exceptions.*;
2323
import io.reactivex.rxjava3.functions.*;
2424
import io.reactivex.rxjava3.internal.subscriptions.*;
2525
import io.reactivex.rxjava3.internal.util.*;
@@ -152,7 +152,7 @@ public final void onNext(T t) {
152152
if (sourceMode != QueueSubscription.ASYNC) {
153153
if (!queue.offer(t)) {
154154
upstream.cancel();
155-
onError(new IllegalStateException("Queue full?!"));
155+
onError(new QueueOverflowException());
156156
return;
157157
}
158158
}

src/main/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableConcatMapEager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public void innerNext(InnerQueuedSubscriber<R> inner, R value) {
200200
drain();
201201
} else {
202202
inner.cancel();
203-
innerError(inner, new MissingBackpressureException());
203+
innerError(inner, MissingBackpressureException.createDefault());
204204
}
205205
}
206206

src/main/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableConcatMapScheduler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.reactivestreams.*;
2020

2121
import io.reactivex.rxjava3.core.*;
22-
import io.reactivex.rxjava3.exceptions.Exceptions;
22+
import io.reactivex.rxjava3.exceptions.*;
2323
import io.reactivex.rxjava3.functions.*;
2424
import io.reactivex.rxjava3.internal.operators.flowable.FlowableConcatMap.*;
2525
import io.reactivex.rxjava3.internal.subscriptions.SubscriptionHelper;
@@ -151,7 +151,7 @@ public final void onNext(T t) {
151151
if (sourceMode != QueueSubscription.ASYNC) {
152152
if (!queue.offer(t)) {
153153
upstream.cancel();
154-
onError(new IllegalStateException("Queue full?!"));
154+
onError(new QueueOverflowException());
155155
return;
156156
}
157157
}

src/main/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableCreate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static final class ErrorAsyncEmitter<T> extends NoOverflowBaseAsyncEmitter<T> {
442442

443443
@Override
444444
void onOverflow() {
445-
onError(new MissingBackpressureException("create: could not emit value due to lack of requests"));
445+
onError(new MissingBackpressureException("create: " + MissingBackpressureException.DEFAULT_MESSAGE));
446446
}
447447

448448
}

src/main/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableDebounce.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void emit(long idx, T value) {
148148
BackpressureHelper.produced(this, 1);
149149
} else {
150150
cancel();
151-
downstream.onError(new MissingBackpressureException("Could not deliver value due to lack of requests"));
151+
downstream.onError(MissingBackpressureException.createDefault());
152152
}
153153
}
154154
}

0 commit comments

Comments
 (0)