--- a/jdk/src/share/classes/java/io/DeleteOnExitHook.java Thu Apr 23 19:44:43 2009 +0100
+++ b/jdk/src/share/classes/java/io/DeleteOnExitHook.java Mon Apr 27 12:08:41 2009 -0700
@@ -34,23 +34,31 @@
*/
class DeleteOnExitHook {
+ private static LinkedHashSet<String> files = new LinkedHashSet<String>();
static {
- sun.misc.SharedSecrets.getJavaLangAccess()
- .registerShutdownHook(2 /* Shutdown hook invocation order */,
- new Runnable() {
- public void run() {
- runHooks();
- }
- });
+ // DeleteOnExitHook must be the last shutdown hook to be invoked.
+ // Application shutdown hooks may add the first file to the
+ // delete on exit list and cause the DeleteOnExitHook to be
+ // registered during shutdown in progress. So set the
+ // registerShutdownInProgress parameter to true.
+ sun.misc.SharedSecrets.getJavaLangAccess()
+ .registerShutdownHook(2 /* Shutdown hook invocation order */,
+ true /* register even if shutdown in progress */,
+ new Runnable() {
+ public void run() {
+ runHooks();
+ }
+ }
+ );
}
- private static LinkedHashSet<String> files = new LinkedHashSet<String>();
-
private DeleteOnExitHook() {}
static synchronized void add(String file) {
- if(files == null)
+ if(files == null) {
+ // DeleteOnExitHook is running. Too late to add a file
throw new IllegalStateException("Shutdown in progress");
+ }
files.add(file);
}