JDK-6189812 : Java2D: createFont temporary font files still open on exit aren't removed on windows
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: generic
  • Submitted: 2004-11-03
  • Updated: 2010-04-02
  • Resolved: 2004-11-22
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.
JDK 6
6 b14Fixed
Related Reports
Relates :  
Description
File.deleteOnExit is used to remove temporary font files created
by the implementation of Font.createFont.

That implementation is run via a shutdown hook on normal exit only.
On windows files that are open cannot be deleted and deleteOnExit
doesn't make any attempt to close open files first - it doesn't
know which streams correspond to this file and probably can't
easily determine this?)
So using this default implementation has several problems.
- If the app happens to be using the font file, and it is still open
the temp file can't be deleted
- you can't remove a file from the File.deleteOnExit list so in
the event an app makes a lot of use of this API we end up with
lots of files on the list that were probably removed earlier when
all references were removed and finalisers run
- if an app ends abnormally the shutdown hook isn't run.

So at the least we should try to close the font files so that the
deleteOnExit hook can remove them. The obvious way to do this
is with our own shutdown hook which closes the files. But there
is no guarantee which hook will run first! In fact all shutdown
hook threads are by spec started in unspecified order and
run concurrently.

So we may as well do everything in our own shutdown hook - close
the files and then remove them, and if files are GC'd and
deleted before shutdown remove them from the list to delete on exit.
Need to be careful only to remove the temporary copies.
We would only install this hook if a temp font file is created.

The deleteOnExit hook is, so far as I can tell, no more likely
to get run on abnormal exits than our own hook - in fact its doc
says its only run on normal termination.

So there is no way we can 100% guarantee temp files are removed
on abnormal termination. But we can guarantee it for normal termination.
###@###.### 11/3/04 00:18 GMT

Comments
EVALUATION As per description ###@###.### 11/3/04 00:19 GMT
03-11-2004