Skip to content

Commit

Permalink
Comment on explicit closing of URLClassLoader instances
Browse files Browse the repository at this point in the history
Specifically, why we need it for benchmarks but not for plugins.
  • Loading branch information
lbulej committed Dec 5, 2024
1 parent fc3a800 commit c83e0ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ private static ClassLoader createClassLoaderFromPaths(
throw new ExtensionException("malformed URL(s) in classpath specification");
}

//
// No need to explicitly close this URLClassLoader on exit, because it does not
// operate on files created by the harness that need to be deleted on exit.
//
ClassLoader parent = ModuleLoader.class.getClassLoader();
return new URLClassLoader(classPathUrls, parent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ ClassLoader createClassLoaderForModule(String name) throws ModuleLoadingExceptio
name, filePaths.size(), makeClassPath(filePaths)
));

//
// Make sure to explicitly close this URLClassLoader on exit, because it operates
// on files created by the harness in the scratch directory hierarchy that need to
// be deleted on exit. Leaving the class loader open keeps the library JAR files
// open, preventing removal of the scratch directories. This is because on NFS,
// deleting an open file produces a NFS temporary file in the same directory, and
// on Windows, an open file cannot be deleted at all.
//
return Cleaner.closeOnExit(new URLClassLoader(urls, thisClass.getClassLoader()));

} catch (IOException e) {
Expand Down

0 comments on commit c83e0ac

Please sign in to comment.