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

PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 14
    • core-libs
    • None
    • behavioral
    • minimal
    • There should be little compatibility risk as the overridden method retains the same behavior and the added method is of course new.
    • Java API
    • SE

    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.

      Attachments

        1. 8187898.patch
          6 kB
        2. write-8187898.png
          write-8187898.png
          102 kB
        3. writeBytes-8187898.png
          writeBytes-8187898.png
          51 kB

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: