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

DataOutputStream.writeUTF may throw unexpected exceptions

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 13
    • core-libs
    • None
    • behavioral
    • minimal
    • Only adds a @throws clause so no compatibility problems should present.
    • Java API
    • SE

      Summary

      DataOutputStream::writeUTF should explicitly document that a UTFDataFormatException is thrown if the input string is too long.

      Problem

      DataOutputStream::writeUTF will throw a UTFDataFormatException exception if the encoded UTF-8 character string is longer than 65535.

      Solution

      Document that DataOutputStream::writeUTF will throw a UTFDataFormatException exception if the encoded UTF-8 character string is longer than 65535.

      Specification

      java.io.DataOutputStream:

      @@ -317,7 +317,10 @@
            * thrice the length of <code>str</code>.
            *
            * @param      str   a string to be written.
      -     * @exception  IOException  if an I/O error occurs.
      +     * @throws     UTFDataFormatException  if the modified UTF-8 encoding of
      +     *             {@code str} would exceed 65535 bytes in length
      +     * @throws     IOException  if some other I/O error occurs.
      +     * @see        #writeChars(String)
            */
           public final void writeUTF(String str) throws IOException {}

            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Lance Andersen, Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: