JDK-6359560 : (fs) File.deleteOnExit() doesn't work when MappedByteBuffer exists (win)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 5.0u6
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-12-06
  • Updated: 2010-09-30
  • Resolved: 2007-10-24
Related Reports
Relates :  
Description
1. create a file by calling File.createNewFile().
2. mark the file, File.deleteOnExit()
3. write something in the file, open it for reading using MappedByteBuffer mapping.
4. close everything, dereference the mapped buffer (that one cannot be directly closed)

5. Error -> depending on how fast you exit the program, the file will or will not be deleted.

I would expect the mapped buffer to be unmapped on shutdown and the file to be released.

Our usecase in netbeans IDE is:
the output window is memory mapped for reading, the output keeps the output tabs open until the user closes them or until he/she closes the whole IDE. 
This is Windows only problem it seems to work correctly on other platforms.

Comments
EVALUATION Sorry, we're tried, but we just don't have a robust solution to this problem. If anyone comes up with a solution that can guarantee that executing threads cannot access the memory after the region has been unmapped then please submit another bug with the details.
24-10-2007

EVALUATION We have attempted to fix this problem by unmapping any mapped regions prior to executing the deleteOnExit hooks. However, this on its own is not a feasible solution as there may still be threads eecuting during the shutdown that are accessing the buffers and this creates the potential for issues as detailed in 4724038.
04-03-2007

EVALUATION Windows keeps internal open handles for each mapped view. As the MappedByteBuffer can't be unmapped (see 4724038) it means these handles aren't closed. On Windows the deleteOnExit mechanism cannot delete open files (see 4171239). It may be possible to unmap all MappedByteBuffers during shutdown (after shutdown hooks have executed but before deleteOnExit runs). It is too late to investigate this for mustang but may be worth examining for dolphin. One other point - the bug description suggests the issue is intermittent. It would be good to get more information or a test case to verify this.
08-12-2005