Code Review 7000511: PrintStream, PrintWriter, Formatter leave files open when exception thrown

Chris Hegarty chris.hegarty at oracle.com
Tue Dec 14 15:07:16 UTC 2010


Failing java.io.PrintStream, java.io.PrintWriter, java.util.Scanner, and 
java.util.Formatter multi-arg constructors that take a java.io.File or 
String filename (as well as one or more additional args) opens a 
FileIn/OutputStream to the given File/filename. If one of the other 
given args causes the constructor to fail ( null or unsupported charset 
for example ) the FileIn/OutputStream is never closed, and the 
application does not have a reference to it. You rely on the finalizer 
to close the stream.

This is most serious on Windows because you cannot remove a file if 
there is an open handle to it.

I also cleaned up an existing regression test that fails in samevm mode 
(partly) because of this. And removed another excluded test from the 
list since its bug was fixed some time ago.

Webrev:
   http://cr.openjdk.java.net/~chegar/7000511/webrev.00/webrev/

-Chris.



More information about the core-libs-dev mailing list