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

InputStream.transferTo() method should specify what the return value should be when the number of bytes transfered is larger than Long.MAX_VALUE

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 21
    • core-libs
    • None
    • behavioral
    • minimal
    • Minimal compatibility risk as transferring more than Long.MAX_VALUE values is unlikely to occur often.
    • Java API
    • SE

    Description

      Summary

      Specify that the transferTo methods of InputStream and Reader in the java.io package and java.util.zip.ZipInputStream::transferTo return at most Long.MAX_VALUE.

      Problem

      InputStream::transferTo and Reader::transferTo may transfer more than Long.MAX_VALUE bytes or characters, respectively, but in both cases, the counter of the number of values transferred will overflow a long.

      Solution

      Clamp the value returned by transferTo to Long.MAX_VALUE and specify that if more than that number of values is transferred, then Long.MAX_VALUE will be returned.

      Specification

      --- a/src/java.base/share/classes/java/io/InputStream.java
      +++ b/src/java.base/share/classes/java/io/InputStream.java
      @@ -769,6 +769,9 @@ public boolean markSupported() {
            * interrupted during the transfer, is highly input and output stream
            * specific, and therefore not specified.
            * <p>
      +     * If the total number of bytes transferred is greater than {@linkplain
      +     * Long#MAX_VALUE}, then {@code Long.MAX_VALUE} will be returned.
      +     * <p>
            * If an I/O error occurs reading from the input stream or writing to the
            * output stream, then it may do so after some bytes have been read or
            * written. Consequently the input stream may not be at end of stream and
      
      --- a/src/java.base/share/classes/java/io/Reader.java
      +++ b/src/java.base/share/classes/java/io/Reader.java
      @@ -421,6 +421,9 @@ public void reset() throws IOException {
            * interrupted during the transfer, is highly reader and writer
            * specific, and therefore not specified.
            * <p>
      +     * If the total number of characters transferred is greater than {@linkplain
      +     * Long#MAX_VALUE}, then {@code Long.MAX_VALUE} will be returned.
      +     * <p>
            * If an I/O error occurs reading from the reader or writing to the
            * writer, then it may do so after some characters have been read or
            * written. Consequently the reader may not be at end of the stream and

      Attachments

        Issue Links

          Activity

            People

              bpb Brian Burkhalter
              jpai Jaikiran Pai
              Alan Bateman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: