JDK-5052087 : (fmt spec) PrintWriter constructors may throw IOExceptions - clarify class doc
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-05-24
  • Updated: 2004-06-10
  • Resolved: 2004-06-10
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 b56Fixed
Related Reports
Relates :  
Description

Name: rmT116609			Date: 05/24/2004


FULL PRODUCT VERSION :
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Win XP, but irrelevant

A DESCRIPTION OF THE PROBLEM :
Javadoc for java.io.PrintWriter says: " Methods in this class never throw I/O exceptions. The client may inquire as to whether any errors have occurred by invoking checkError()."

That is not correct.  Many public methods in PrintWriter throw exceptions,
including both forms of printf and both forms of append().

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Read the javadoc and the source code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
expect javadoc to be consistent with source
ACTUAL -
they are not consistent

REPRODUCIBILITY :
This bug can be reproduced always.
(Incident Review ID: 274810) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-rc FIXED IN: tiger-rc INTEGRATED IN: tiger-b56 tiger-rc
08-07-2004

SUGGESTED FIX *** /tmp/geta20800 Wed Jun 2 14:42:43 2004 --- PrintWriter.java Wed Jun 2 14:32:56 2004 *************** *** 22,29 **** * use the platform's own notion of line separator rather than the newline * character. * ! * <p> Methods in this class never throw I/O exceptions. The client may ! * inquire as to whether any errors have occurred by invoking checkError(). * * @version %I%, %G% * @author Frank Yellin --- 22,30 ---- * use the platform's own notion of line separator rather than the newline * character. * ! * <p> Methods in this class never throw I/O exceptions, although some of its ! * constructors may. The client may inquire as to whether any errors have ! * occurred by invoking checkError(). * * @version %I%, %G% * @author Frank Yellin -- iag@sfbay 2004-06-02
02-06-2004

EVALUATION In Tiger, there were three types of additions to this class: printf/format methods, append methods, and convenience constructors. The printf/format methods have always thrown NullPointerException and IllegalFormatException neither of which is a subtype of IOException. The append methods no longer throw IOExceptions (see bug 5030623 fixed in beta2). All of the new PrintWriter constructors throw FileNotFoundException. Some of the constructors also throw UnsupportedEncodingException. Both of these exceptions are subtypes of IOException, however if the constructor fails to create an object, there is no way to invoke checkError. Furthermore, constructors aren't methods so the class javadoc doesn't apply. The only pre-Tiger method in PrintWriter which is documented to throw an exception is print(char[]). It throws a NullPointerException which, again, is not a subtype of IOException. This bug will likely be closed as a duplicate of 5030623. -- iag@sfbay 2004-06-01 To prevent any misinterpretation of the class javadoc, we'll add a small, clarifying phrase. OLD: Methods in this class never throw I/O exceptions. NEW: Methods in this class never throw I/O exceptions, although some of its constructors may. -- iag@sfbay 2004-06-02
02-06-2004