JDK-8074212 : deleteOnExit is incorrectly deleting my files
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u67
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-11-18
  • Updated: 2021-01-04
  • Resolved: 2015-03-03
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
WDataTransferer.translateBytesOrStream puts relative paths on deleteOnExit list which causes my files (of the same name) to be deleted unexpectedly.


If there is a virtual file on the clipboard.  The formats FILEDESCRIPTOR and FILECONTENTS identify a transferable group of files that are not stored as file system files (virtual). It is files of these formats on the clipboard that are causing the problem.


From java call:
Transferable.getTransferData (Java public api) using DataFlavor.javaFileListFlavor (requesting to transfer a file or list of files)

WDataTransferer.translateBytesOrStream calls

File.deleteOnExit (called on file objects constructed using relative paths found on the clipboard)

When file names are stored as relative paths on the deleteOnExit list, at jvm shutdown, real files of the same name in the folder  are  deleted.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac the code supplied below in the test case section.

Using windows explorer,  view a folder containing a zip file.  In my case I have a zip file containing one file,  foo.txt

right click and select Open With Windows Explorer

select foo.txt from within the zip file and and right-click to copy the file to the clipboard.

Run the reproducible java code from a folder that also contains a file called foo.txt.

(note Copy and Paste using Remote Desktop also uses these virtual files and leads to the same file delete problem)


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Relative file paths in the delete on exist shouldn't be there, and definitely shouldn't be deleting the files in my folder that I am not expecting to be deleted. 
Run the test and your file, in my case foo.txt, will be deleted on jvm exit.

ACTUAL -
my file, foo.txt is deleted and shouldn't be.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.io.File;
import java.util.List;
import java.awt.datatransfer.Clipboard;

public class testJavaBug {
    public static void main(String[] args) {
        try {
		// delete file bug happens using either getTransferData or Clipboard.getData
		
		    Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
		    Object data = transferable.getTransferData( DataFlavor.javaFileListFlavor );
     
		//	Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
		//	if (cb.isDataFlavorAvailable(DataFlavor.javaFileListFlavor)) {
		//		List files = (List) cb.getData(DataFlavor.javaFileListFlavor);
        //  }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}
		  
---------- END SOURCE ----------


Comments
Not able to repro by following the repro steps provided. Tested with JDK7u25-b17, and JDK9 on Windows 7 64bit system with 32 bit Java. The file (Exactly same file as the one on clipboard but different location) in the folder that the repro source code runs from stays after java code runs. No file is deleted. Closed as can not repro.
16-12-2014