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

Athijegannathan Sundararajan sundar at openjdk.java.net
Tue Jun 8 13:05:14 UTC 2021


On Tue, 8 Jun 2021 12:20:32 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

> 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 {
> ```

Thanks @JornVernee

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

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


More information about the core-libs-dev mailing list