JDK-8221428 : DataOutputStream.writeUTF may throw unexpected exceptions
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.io
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 13
  • Submitted: 2019-03-25
  • Updated: 2019-03-26
  • Resolved: 2019-03-26
Related Reports
CSR :  
Description
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 {}
```


Comments
Re-approving updated request.
26-03-2019

As a code review comment, please consider adding a javadoc @see/@link to writeChars��� which doesn't appear to suffer from this 64k limitation. A release note could be added for this change, but it is probably below the line of changes where it is strictly necessary to do so. Moving to Approved.
26-03-2019