JDK-5030623 : (fmt) {Print{Writer,Stream},StringWriter}.append should not throw IOException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-04-13
  • Updated: 2017-05-16
  • Resolved: 2004-04-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b49Fixed
Related Reports
Relates :  
Relates :  
Description
Print{Writer,Stream}.append and StringWriter.append currently throw IOException.
This is inconsistent with IOException handling for the existing write/print methods in those classes.  The append methods in these cases should be
overridden to omit mention of the IOException.

Writer.append(char) and Writer.append(CharSequence) are missing @throws
for the IOException.

-- iag@sfbay 2004-04-12

CharArrayWriter.append() also inappropriately throw IOException.

-- iag@sfbay 2004-04-15

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta2 FIXED IN: tiger-beta2 INTEGRATED IN: tiger-b49 tiger-beta2
14-06-2004

SUGGESTED FIX {Print,String}Writer.java: SOLUTION: override javadoc and implementation to suppress IOException which would be inherited from Writer OLD (for PrintWriter only, StringWriter did not have override): ! // javadoc inherited from Writer.java ! public PrintWriter append(CharSequence csq) throws IOException { [ ... ] ! // javadoc inherited from Writer.java ! public PrintWriter append(char c) throws IOException { NEW (pure addition for StringWriter and CharArrayWriter): ! /** ! * Appends the specified character sequence to this writer. ! * ! * <p> An invocation of this method of the form <tt>out.append(csq)</tt> ! * behaves in exactly the same way as the invocation ! * ! * <pre> ! * out.write(csq.toString()) </pre> ! * ! * <p> Depending on the specification of <tt>toString</tt> for the ! * character sequence <tt>csq</tt>, the entire sequence may not be ! * appended. For instance, invoking the <tt>toString</tt> method of a ! * character buffer will return a subsequence whose content depends upon ! * the buffer's position and limit. ! * ! * @param csq ! * The character sequence to append. If <tt>csq</tt> is ! * <tt>null</tt>, then the four characters <tt>"null"</tt> are ! * appended to this writer. ! * ! * @return This writer ! * ! * @since 1.5 ! */ ! public PrintWriter append(CharSequence csq) { [ ... ] ! ! /** ! * Appends the specified character to this writer. ! * ! * <p> An invocation of this method of the form <tt>out.append(c)</tt> ! * behaves in exactly the same way as the invocation ! * ! * <pre> ! * out.write(c) </pre> ! * ! * @param c ! * The 16-bit character to append ! * ! * @return This writer ! * ! * @since 1.5 ! */ ! public PrintWriter append(char c) { PrintStream.java: SOLUTION: remove IOException from specification and method signature OLD: * * @return This character stream * - * @throws IOException - * If an I/O error occurs - * * @since 1.5 */ ! public PrintStream append(CharSequence csq) throws IOException { [ ... ] - * @throws IOException - * If an I/O error occurs - * * @since 1.5 */ ! public PrintStream append(char c) throws IOException { NEW: * * @return This character stream * * @since 1.5 */ ! public PrintStream append(CharSequence csq) { [ ... ] * * @return This output stream * * @since 1.5 */ ! public PrintStream append(char c) { Writer.java SOLUTION: add @throws to append methods OLD: ! * appended to this text-output stream. * NEW: ! * appended to this writer. * * @return This writer * + * @throws IOException + * If an I/O error occurs + * * @since 1.5 */ public Writer append(CharSequence csq) throws IOException { [ ... ] * The 16-bit character to append * * @return This writer + * + * @throws IOException + * If an I/O error occurs * * @since 1.5 */ Formatter.java SOLUTION: add the following clarification text to ioException() NEW: + * <p> If the destination's <tt>append()</tt> method never throws + * <tt>IOException</tt>, then this method will always return <tt>null</tt>. -- iag@sfbay 2004-04-12
12-04-2004

EVALUATION The suggested fix is correct. -- iag@sfbay 2004-04-12
12-04-2004