changeset 14316:1943b3022700

Fix for 81422389. Close archives in all cases. Reviewed-by: jlaskey
author jfdenise
date Tue, 10 Nov 2015 14:43:25 +0100
parents 8daa6a6c8657
children 1b50ccfd6f27 30cae8145c33
files src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
diffstat 1 files changed, 39 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java	Tue Nov 10 11:06:42 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java	Tue Nov 10 14:43:25 2015 +0100
@@ -126,46 +126,52 @@
             Set<Archive> archives,
             ImagePluginStack pluginSupport)
             throws IOException {
-        Map<String, List<Entry>> entriesForModule
-                = archives.stream().collect(Collectors.toMap(
-                                Archive::moduleName,
-                                a -> {
-                                    try(Stream<Entry> entries = a.entries()) {
-                                        return entries.collect(Collectors.toList());
-                                    }
-                                }));
-        ByteOrder order = ByteOrder.nativeOrder();
-        Pools pools = createPools(archives, entriesForModule, order);
-        try (OutputStream fos = Files.newOutputStream(jimageFile);
-                BufferedOutputStream bos = new BufferedOutputStream(fos);
-                DataOutputStream out = new DataOutputStream(bos)) {
-            BasicImageWriter writer = new BasicImageWriter(order);
-            generateJImage(pools.resources, writer, pluginSupport, out);
-        }
-        //Close all archives
-        for(Archive a : archives) {
-            a.close();
+        try {
+            Map<String, List<Entry>> entriesForModule
+                    = archives.stream().collect(Collectors.toMap(
+                                    Archive::moduleName,
+                                    a -> {
+                                        try (Stream<Entry> entries = a.entries()) {
+                                            return entries.collect(Collectors.toList());
+                                        }
+                                    }));
+            ByteOrder order = ByteOrder.nativeOrder();
+            Pools pools = createPools(archives, entriesForModule, order);
+            try (OutputStream fos = Files.newOutputStream(jimageFile);
+                    BufferedOutputStream bos = new BufferedOutputStream(fos);
+                    DataOutputStream out = new DataOutputStream(bos)) {
+                BasicImageWriter writer = new BasicImageWriter(order);
+                generateJImage(pools.resources, writer, pluginSupport, out);
+            }
+        } finally {
+            //Close all archives
+            for (Archive a : archives) {
+                a.close();
+            }
         }
     }
 
     private void writeImage(Set<Archive> archives,
             ByteOrder byteOrder)
             throws IOException {
-        Pools pools = createPools(archives,
-                entriesForModule, byteOrder);
-        BasicImageWriter writer = new BasicImageWriter(byteOrder);
-        ResourcePool result = generateJImage(pools.resources,
-                writer, plugins, plugins.getJImageFileOutputStream());
+        try {
+            Pools pools = createPools(archives,
+                    entriesForModule, byteOrder);
+            BasicImageWriter writer = new BasicImageWriter(byteOrder);
+            ResourcePool result = generateJImage(pools.resources,
+                    writer, plugins, plugins.getJImageFileOutputStream());
 
-        //Handle files.
-        try {
-            plugins.storeFiles(pools.files, result, writer);
-        } catch (Exception ex) {
-            throw new IOException(ex);
-        }
-        //Close all archives
-        for(Archive a : archives) {
-            a.close();
+            //Handle files.
+            try {
+                plugins.storeFiles(pools.files, result, writer);
+            } catch (Exception ex) {
+                throw new IOException(ex);
+            }
+        } finally {
+            //Close all archives
+            for (Archive a : archives) {
+                a.close();
+            }
         }
     }