# HG changeset patch # User iignatyev # Date 1492571454 25200 # Node ID e33ea5371600bcd297d189a01c4c25e37bc34425 # Parent cb3afb654b77f6e2954f627fda595e1c3fe0fcd2 8178913: CTW library does not close all opened resources Reviewed-by: kvn diff -r cb3afb654b77 -r e33ea5371600 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarEntry.java --- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarEntry.java Tue Apr 18 23:52:58 2017 +0200 +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarEntry.java Tue Apr 18 20:10:54 2017 -0700 @@ -54,8 +54,7 @@ if (!Files.exists(root)) { return; } - try { - JarFile jarFile = new JarFile(root.toFile()); + try (JarFile jarFile = new JarFile(root.toFile())) { JarEntry entry; for (Enumeration e = jarFile.entries(); e.hasMoreElements(); ) { diff -r cb3afb654b77 -r e33ea5371600 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJimageEntry.java --- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJimageEntry.java Tue Apr 18 23:52:58 2017 +0200 +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJimageEntry.java Tue Apr 18 20:10:54 2017 -0700 @@ -54,8 +54,7 @@ if (!Files.exists(root)) { return; } - try { - ImageReader reader = ImageReader.open(root); + try (ImageReader reader = ImageReader.open(root)) { Arrays.stream(reader.getEntryNames()) .filter(name -> name.endsWith(".class")) .filter(name -> !name.endsWith("module-info.class")) diff -r cb3afb654b77 -r e33ea5371600 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java --- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java Tue Apr 18 23:52:58 2017 +0200 +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java Tue Apr 18 20:10:54 2017 -0700 @@ -90,6 +90,10 @@ } catch (Throwable t){ t.printStackTrace(ERR); } finally { + try { + OUT.close(); + } catch (Throwable ignore) { + } // might have started new threads System.exit(passed ? 0 : 1); } diff -r cb3afb654b77 -r e33ea5371600 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java --- a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java Tue Apr 18 23:52:58 2017 +0200 +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java Tue Apr 18 20:10:54 2017 -0700 @@ -27,6 +27,7 @@ import jdk.test.lib.process.ProcessTools; import jdk.test.lib.util.Pair; +import java.io.BufferedReader; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -145,11 +146,11 @@ } private Pair getLastClass(Path errFile) { - try { - String line = Files.newBufferedReader(errFile) - .lines() + try (BufferedReader reader = Files.newBufferedReader(errFile)) { + String line = reader.lines() .filter(IS_CLASS_LINE) - .reduce((a, b) -> b).orElse(null); + .reduce((a, b) -> b) + .orElse(null); if (line != null) { int open = line.indexOf('[') + 1; int close = line.indexOf(']');