RFR: 8240349: jlink --vm with not present VM does not fail fast

Jorn Vernee jvernee at openjdk.java.net
Tue Jun 8 12:23:21 UTC 2021


On Mon, 7 Jun 2021 11:00:00 GMT, Athijegannathan Sundararajan <sundar at openjdk.org> wrote:

> jlink should clean up output directory on any failure. should not leave partially filled output.

WRT the test failure on Windows discussed offline: when the directory is deleted as a result of a `PluginException` being thrown, there is still an open file handle on the `lib/modules` file in the image directory, which prevents the directory from being deleted.

Bisecting this, it seems that the file handle is being created in `ImageFileCreater::writeImage` with a call to `plugins.getJImageFileOutputStream` (https://github.com/openjdk/jdk/blob/master/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java#L162). This creates an output stream that is never closed.

Following patch fixes:

diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
index 749025bea9d..8beddc5a037 100644
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
@@ -158,8 +158,10 @@ public final class ImageFileCreator {
         BasicImageWriter writer = new BasicImageWriter(byteOrder);
         ResourcePoolManager allContent = createPoolManager(archives,
                 entriesForModule, byteOrder, writer);
-        ResourcePool result = generateJImage(allContent,
-             writer, plugins, plugins.getJImageFileOutputStream());
+        ResourcePool result;
+        try (DataOutputStream out = plugins.getJImageFileOutputStream()) {
+            result = generateJImage(allContent, writer, plugins, out);
+        }

         //Handle files.
         try {

-------------

PR: https://git.openjdk.java.net/jdk/pull/4386


More information about the core-libs-dev mailing list