mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-13 06:59:38 +00:00
8176303: Flow.Subscription.request(0) should be treated as an error
Reviewed-by: martin, chegar
This commit is contained in:
parent
e9955f7e3c
commit
2accd8450e
@ -271,11 +271,11 @@ public final class Flow {
|
||||
/**
|
||||
* Adds the given number {@code n} of items to the current
|
||||
* unfulfilled demand for this subscription. If {@code n} is
|
||||
* negative, the Subscriber will receive an {@code onError}
|
||||
* signal with an {@link IllegalArgumentException} argument.
|
||||
* Otherwise, the Subscriber will receive up to {@code n}
|
||||
* additional {@code onNext} invocations (or fewer if
|
||||
* terminated).
|
||||
* less than or equal to zero, the Subscriber will receive an
|
||||
* {@code onError} signal with an {@link
|
||||
* IllegalArgumentException} argument. Otherwise, the
|
||||
* Subscriber will receive up to {@code n} additional {@code
|
||||
* onNext} invocations (or fewer if terminated).
|
||||
*
|
||||
* @param n the increment of demand; a value of {@code
|
||||
* Long.MAX_VALUE} may be considered as effectively unbounded
|
||||
|
||||
@ -1365,9 +1365,9 @@ public class SubmissionPublisher<T> implements Flow.Publisher<T>,
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (n < 0L)
|
||||
else
|
||||
onError(new IllegalArgumentException(
|
||||
"negative subscription request"));
|
||||
"non-positive subscription request"));
|
||||
}
|
||||
|
||||
public final boolean isReleasable() { // for ManagedBlocker
|
||||
|
||||
@ -560,17 +560,21 @@ public class SubmissionPublisherTest extends JSR166TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Negative request causes error
|
||||
* Non-positive request causes error
|
||||
*/
|
||||
public void testRequest3() {
|
||||
SubmissionPublisher<Integer> p = basicPublisher();
|
||||
TestSubscriber s1 = new TestSubscriber();
|
||||
TestSubscriber s2 = new TestSubscriber();
|
||||
TestSubscriber s3 = new TestSubscriber();
|
||||
p.subscribe(s1);
|
||||
p.subscribe(s2);
|
||||
p.subscribe(s3);
|
||||
s3.awaitSubscribe();
|
||||
s2.awaitSubscribe();
|
||||
s1.awaitSubscribe();
|
||||
s1.sn.request(-1L);
|
||||
s3.sn.request(0L);
|
||||
p.submit(1);
|
||||
p.submit(2);
|
||||
p.close();
|
||||
@ -580,6 +584,9 @@ public class SubmissionPublisherTest extends JSR166TestCase {
|
||||
s1.awaitError();
|
||||
assertEquals(1, s1.errors);
|
||||
assertTrue(s1.lastError instanceof IllegalArgumentException);
|
||||
s3.awaitError();
|
||||
assertEquals(1, s3.errors);
|
||||
assertTrue(s3.lastError instanceof IllegalArgumentException);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user