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

InflaterInputStream.skip receives long but it's limited to Integer.MAX_VALUE

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 23, 24
    • core-libs
    • None
    • behavioral
    • minimal
    • Hide
      The update to the API specification of InflaterInputStream.skip() method is merely to specify the current implementation of that method. As such, this change does not cause behavioural changes. The update is specified using an "@implNote". So, any sub-classes that override this method would not be forced to update their implementation to match this behaviour.
      Show
      The update to the API specification of InflaterInputStream.skip() method is merely to specify the current implementation of that method. As such, this change does not cause behavioural changes. The update is specified using an "@implNote". So, any sub-classes that override this method would not be forced to update their implementation to match this behaviour.
    • Java API
    • SE

      Summary

      The API specification of java.util.zip.InflaterInputStream.skip(long) method will be updated to specify that it will skip at most Integer.MAX_VALUE bytes.

      Problem

      InflaterInputStream.skip(long) method takes a long value representing the number of bytes to skip from the compressed stream. In its current implementation, the method skips at most Integer.MAX_VALUE bytes, even when the compressed stream may have more bytes that could be skipped. This implementation detail isn't specified in the API documentation of that method.

      java.util.zip.DeflaterInputStream has a similar skip(long) method whose implementation too takes a long value and skips at most Integer.MAX_VALUE bytes. That method however, clearly notes this detail in its API documentation which states (among other things):

      <em>Note:</em> While {@code n} is given as a {@code long},
      * the maximum number of bytes which can be skipped is
      * {@code Integer.MAX_VALUE}.

      Solution

      The API specification of InflaterInputStream.skip(long) will be updated to specify the current implementation detail that it will skip at most Integer.MAX_VALUE bytes. While at it, the API documentation of this method will also be updated to state that method may block until the specified number of bytes are read and skipped. This change too is merely stating the current implementation detail, like what the DeflaterInputStream.skip(long) already does.

      Specification

          diff --git a/src/java.base/share/classes/java/util/zip/DeflaterInputStream.java b/src/java.base/share/classes/java/util/zip/DeflaterInputStream.java
      
           /**
            * Skips over and discards data from the input stream.
      -     * This method may block until the specified number of bytes are read and
      -     * skipped. <em>Note:</em> While {@code n} is given as a {@code long},
      -     * the maximum number of bytes which can be skipped is
      -     * {@code Integer.MAX_VALUE}.
      +     * This method may block until the specified number of bytes are skipped
      +     * or end of stream is reached.
            *
      -     * @param n number of bytes to be skipped
      -     * @return the actual number of bytes skipped
      +     * @implNote
      +     * This method skips at most {@code Integer.MAX_VALUE} bytes.
      +     *
      +     * @param n number of bytes to be skipped. If {@code n} is zero then no bytes are skipped.
      +     * @return the actual number of bytes skipped, which might be zero
            * @throws IOException if an I/O error occurs or if this stream is
      -     * already closed
      +     *                     already closed
      +     * @throws IllegalArgumentException if {@code n < 0}
            */
           public long skip(long n) throws IOException {
      
      diff --git a/src/java.base/share/classes/java/util/zip/InflaterInputStream.java b/src/java.base/share/classes/java/util/zip/InflaterInputStream.java
      
           /**
            * Skips specified number of bytes of uncompressed data.
      -     * @param n the number of bytes to skip
      -     * @return the actual number of bytes skipped.
      -     * @throws    IOException if an I/O error has occurred
      +     * This method may block until the specified number of bytes are skipped
      +     * or end of stream is reached.
      +     *
      +     * @implNote
      +     * This method skips at most {@code Integer.MAX_VALUE} bytes.
      +     *
      +     * @param n the number of bytes to skip. If {@code n} is zero then no bytes are skipped.
      +     * @return the actual number of bytes skipped, which might be zero
      +     * @throws IOException if an I/O error occurs or if this stream is
      +     *                     already closed
            * @throws    IllegalArgumentException if {@code n < 0}
            */
           public long skip(long n) throws IOException {

            jpai Jaikiran Pai
            webbuggrp Webbug Group
            Alan Bateman, Lance Andersen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: