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

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

    Details

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

      Backports

        Description

        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

          Activity

          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/f80fadfa33c3
          User: lana
          Date: 2017-03-15 14:49:32 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/f80fadfa33c3 User: lana Date: 2017-03-15 14:49:32 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/f80fadfa33c3
          User: martin
          Date: 2017-03-10 17:15:42 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/f80fadfa33c3 User: martin Date: 2017-03-10 17:15:42 +0000
          Hide
          chegar Chris Hegarty added a comment -
          CCC has been approved. Martin, you are cleared to push to jdk9/dev.
          Show
          chegar Chris Hegarty added a comment - CCC has been approved. Martin, you are cleared to push to jdk9/dev.
          Hide
          chegar Chris Hegarty added a comment -
          Thanks Doug and Martin. The changes in the above webrev look good. I'll file a CCC for the clarification and let you know when it has been approved.
          Show
          chegar Chris Hegarty added a comment - Thanks Doug and Martin. The changes in the above webrev look good. I'll file a CCC for the clarification and let you know when it has been approved.
          Show
          martin Martin Buchholz added a comment - http://cr.openjdk.java.net/~martin/webrevs/openjdk9/jsr166-jdk9-integration/requestZero/
          Hide
          dl Doug Lea added a comment -
          I have only myself to blame for not noticing that the approved reactive-streams.org spec needlessly rejects request(0). But given that it does, the JDK spec and implementation should as well. Now changed in our CVS, with an additional check in tck tests.
          Show
          dl Doug Lea added a comment - I have only myself to blame for not noticing that the approved reactive-streams.org spec needlessly rejects request(0). But given that it does, the JDK spec and implementation should as well. Now changed in our CVS, with an additional check in tck tests.
          Hide
          chegar Chris Hegarty added a comment -
          This, if needed, is a minor spec tweak to a new type in 9. It would be good to do this in 9, if needed, rather than try to fix it up in a later release.
          Show
          chegar Chris Hegarty added a comment - This, if needed, is a minor spec tweak to a new type in 9. It would be good to do this in 9, if needed, rather than try to fix it up in a later release.

            People

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

              Dates

              • Created:
                Updated:
                Resolved: