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

java.io.InputStream.skip() can throw NegativeArraySizeException or return -1

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1, 1.1.3
    • core-libs
    • x86, sparc
    • solaris_2.5, windows_95, windows_nt

      The implementation of skip() in java.io.InputStream:

          public long skip(long n) throws IOException {
              /* ensure that the number is a positive int */
              byte data[] = new byte[(int) (n & 0xEFFFFFFF)];
              return read(data);
          }

      First off, the bit mask above must just be a typo; it should be 0x7FFFFFFF.
      As it is, it allows negative integers to be used for the array size, resulting
      in a NegativeArraySizeException.

      Second, since it calls read(), it could return -1 if there is EOF before any
      bytes could be skipped. [Although I would argue that this is the way it
      *should* be,] the JLS states that it should still return only zero in this
      case (section 22.3.4).

            mr Mark Reinhold
            peterjones Peter Jones (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: