8176303: Flow.Subscription.request(0) should be treated as an error

Reviewed-by: martin, chegar
This commit is contained in:
Doug Lea 2017-03-10 08:59:14 -08:00
parent e9955f7e3c
commit 2accd8450e
3 changed files with 15 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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);
}
/**