changeset 46391:e33ea5371600

8178913: CTW library does not close all opened resources Reviewed-by: kvn
author iignatyev
date Tue, 18 Apr 2017 20:10:54 -0700
parents cb3afb654b77
children d5572756efd6
files hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarEntry.java hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJimageEntry.java hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java
diffstat 4 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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<JarEntry> e = jarFile.entries();
                     e.hasMoreElements(); ) {
--- 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"))
--- 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) {
+            }
             // <clinit> might have started new threads
             System.exit(passed ? 0 : 1);
         }
--- 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<String, Long> 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(']');