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

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 1.1, 1.1.3
    • Component/s: 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).

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: