Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8176303

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


    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs



        java.util.concurrent Flow is an implementation of reactive-streams specification and as such must conform to rule #9 for Subscription:

        "While the Subscription is not cancelled, Subscription.request(long n) MUST signal onError with a java.lang.IllegalArgumentException if the argument is <= 0. The cause message MUST include a reference to this rule and/or quote the full rule.

        The intent of this rule is to prevent faulty implementations to proceed operation without any exceptions being raised. Requesting a negative or 0 number of elements, since requests are additive, most likely to be the result of an erroneous calculation on the behalf of the Subscriber."

        However, current javadoc states that:

             * 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).
             * @param n the increment of demand; a value of {@code
             * Long.MAX_VALUE} may be considered as effectively unbounded
            public void request(long n);

        i.e. only negative values of n are treated as erroneous.
        This issues was created as a result of this discussion: http://cs.oswego.edu/pipermail/concurrency-interest/2017-March/015642.html


            Issue Links



                • Assignee:
                  martin Martin Buchholz
                  prappo Pavel Rappo
                • Votes:
                  0 Vote for this issue
                  7 Start watching this issue


                  • Created: