JDK-4406042 : File.deleteOnExit() doesn't work in java plug-in.
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_98
  • CPU: x86
  • Submitted: 2001-01-19
  • Updated: 2001-02-15
  • Resolved: 2001-02-15
Related Reports
Relates :  
Description

Name: yyT116575			Date: 01/18/2001


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)


i have write the follow code and try to run it in appletviewer and plug-in


--- VcApplet.java ---
/*
<applet archive=VcApplet.jar code=VcApplet.class
	width=100 height=100>
</applet>
*/


import java.io.*;
import javax.swing.*;
import java.awt.*;

public class VcApplet extends JApplet {
  public void init() {
    System.out.println("Calling init()...");
    File tmpFile;
    FileOutputStream fos;
    DataOutputStream dos;
    byte b[];
    int rc;
    b = new byte[200];

    try {
      tmpFile = File.createTempFile("abc", ".tmp");
      System.out.println("Path=" + tmpFile.getPath() + "Name=" + tmpFile.getName());
      tmpFile.deleteOnExit();

      fos = new FileOutputStream(tmpFile);
      dos = new DataOutputStream(fos);

      dos.write(b, 0, 200);
      dos.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
		
  }

  public void destroy() {
    System.out.println("Calling destroy()...");
  }
}
--- end here ---

I signed it and run it in both appletviewer and netscape with Java plug-in
1.3.0-C.

The 'tmpFile' is not removed when run in Java plug-in even after I completely
closed the netscape. It works find with appletviewer.
(Review ID: 108361) 
======================================================================

Comments
EVALUATION Code specified in the beginning of VcApplet uses <applet> tag. In order to use Java Plug-in OBJECT/EMBED tag should be used instead of <applet> tag. I converted user's applet with HTMLConverter, so that it would use OBJECT/EMBED tags, and tried to reproduce this bug. When Java Plug-in is used, VcApplet creates file, file exists while vm is running. Once you started the vm, it will be running until you close the browser. When I closed the browser, the file was deleted. Note: in JDK tutorial there is a condition for File.deleteOnExit() function - vm must terminate normally. So, if the browser crushes or vm dies, the file VcApplet created might not be deleted. margarita.fisher@East 2001-02-15
15-02-2001

SUGGESTED FIX This is not a Java Plug-in bug. The customer should get HTMLConverter (http://java.sun.com/products), convert his/her applet to use OBJECT/EMBED tag. margarita.fisher@East 2001-02-15
15-02-2001