United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6359560 : (fs) File.deleteOnExit() doesn't work when MappedByteBuffer exists (win)

Details
Type:
Bug
Submit Date:
2005-12-06
Status:
Closed
Updated Date:
2010-09-30
Project Name:
JDK
Resolved Date:
2007-10-24
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.nio
CPU:
x86
Priority:
P4
Resolution:
Won't Fix
Affected Versions:
5.0u6
Fixed Versions:

Related Reports
Relates:

Sub Tasks

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.
                                     
2007-10-24
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.
                                     
2007-03-04
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.
                                     
2005-12-08



Hardware and Software, Engineered to Work Together