JDK-8230625 : PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.io
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 14
  • Submitted: 2019-09-04
  • Updated: 2019-09-09
  • Resolved: 2019-09-05
Related Reports
CSR :  
Description
Summary
-------

Override `write(byte[])` and add `writeBytes`.

Problem
-------

`java.io.PrintStream` was supposed to override methods not to throw `IOException` as indicated in the class documentation:

```Unlike other output streams, a PrintStream never throws an IOException; instead, exceptional situations merely set an internal flag that can be tested via the checkError method.```

The method `write(byte[])` of `java.io.FilterOutputStream` was, however, *not* so overridden. The method is therefore documented as throwing `IOException` but never does so.

Also, there is no `write` method which has only a byte array parameter and which is *not* declared to throw `IOException`. Callers are thus obliged in this scenario to write a try-catch block even though `IOException` will never be thrown.

Solution
--------

Override `write(byte[])` adding clarifying documentation while retaining the existing behavior, and add `writeBytes`.

Specification
-------------

Please refer to the specifications of `write(byte[])` and `writeBytes` in the attachments.


Comments
Attachments updated to include @since tag on write(byte[]).
05-09-2019

As an override with its own javadoc, I think "@since 14" is warranted. Moving to Approved; please update the @since tag before pushing.
05-09-2019

Unsure whether write(byte[]) needs "@since 14" as it is an override.
05-09-2019