< prev index next >

test/hotspot/jtreg/compiler/jsr292/RedefineMethodUsedByMultipleMethodHandles.java

Print this page
rev 52334 : 8204521: compiler/jsr292/RedefineMethodUsedByMultipleMethodHandles.java fails trying to delete temp file

@@ -113,20 +113,19 @@
         Attributes mainAttrs = manifest.getMainAttributes();
         mainAttrs.putValue("Agent-Class", FooAgent.class.getName());
         mainAttrs.putValue("Can-Redefine-Classes", "true");
         mainAttrs.putValue("Can-Retransform-Classes", "true");
 
-        Path jar = Files.createTempFile("myagent", ".jar");
-        try {
+        // The jar file will be added to the system classloader search path.  It is not safe
+        // to delete it while the JVM is running, so make sure to create it in the test
+        // directory so it will be cleaned up by the test harness.
+        Path jar = Files.createTempFile(Path.of(""), "myagent", ".jar");
             JarOutputStream jarStream = new JarOutputStream(new FileOutputStream(jar.toFile()), manifest);
             add(jarStream, FooAgent.class);
             add(jarStream, FooTransformer.class);
             jarStream.close();
             runAgent(jar);
-        } finally {
-            Files.deleteIfExists(jar);
-        }
     }
 
     public static void runAgent(Path agent) throws Exception {
         String vmName = ManagementFactory.getRuntimeMXBean().getName();
         int p = vmName.indexOf('@');
< prev index next >