8176303: Flow.Subscription.request(0) should be treated as an error
Reviewed-by: martin, chegar
--- a/jdk/src/java.base/share/classes/java/util/concurrent/Flow.java Thu Mar 09 23:16:22 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/Flow.java Fri Mar 10 08:59:14 2017 -0800
@@ -271,11 +271,11 @@
/**
* 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
--- a/jdk/src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java Thu Mar 09 23:16:22 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java Fri Mar 10 08:59:14 2017 -0800
@@ -1365,9 +1365,9 @@
}
}
}
- else if (n < 0L)
+ else
onError(new IllegalArgumentException(
- "negative subscription request"));
+ "non-positive subscription request"));
}
public final boolean isReleasable() { // for ManagedBlocker
--- a/jdk/test/java/util/concurrent/tck/SubmissionPublisherTest.java Thu Mar 09 23:16:22 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/SubmissionPublisherTest.java Fri Mar 10 08:59:14 2017 -0800
@@ -560,17 +560,21 @@
}
/**
- * 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 @@
s1.awaitError();
assertEquals(1, s1.errors);
assertTrue(s1.lastError instanceof IllegalArgumentException);
+ s3.awaitError();
+ assertEquals(1, s3.errors);
+ assertTrue(s3.lastError instanceof IllegalArgumentException);
}
/**