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

java.io.EOFException: doc clarification

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • core-libs
    • None
    • beta
    • generic
    • generic
    • Verified

      The javadoc for java.io.EOFException states:

      "Signals that an end of file or end of stream has been reached unexpectedly
       during input.

       This exception is mainly used by data input streams, which generally expect a
       binary file in a specific format, and for which an end of stream is an unusual
       condition. Most other input streams return a special value on end of stream."

      However, DataInputStream.readInt, DataInputStream.readBoolean, etc. have no
      way of signalling an end-of-file condition except by throwing this exception.
      A typical reading loop from a DataInput stream is:

      try {
      for (;;) {
      int i = in.readInt();
      // ...
      }
      } catch (EOFException e) {
      in.close();
      } catch (IOException e) {
      // ... handle an error
      }

      This is in contrast to the typical InputStream or Reader loop:

      try {
      while ((ch = in.read()) != -1)
      // ...
      in.close();
      } catch (IOException e) {
      // ... handle an error
      }

      This behavior is noted in the Java Programming Language, 2nd Edition, Gosling/
      Arnold, Sec. 12.21, p. 256.

      Since an EOFException can be thrown in this expected situation, the javadoc
      should be updated to reflect this.

            mmcclosksunw Michael Mccloskey (Inactive)
            dmendenhsunw David Mendenhall (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: