8178913: CTW library does not close all opened resources

Reviewed-by: kvn
This commit is contained in:
Igor Ignatyev 2017-04-18 20:10:54 -07:00
parent 79793e9c64
commit 154b7f24cb
4 changed files with 11 additions and 8 deletions

View File

@ -54,8 +54,7 @@ public class ClassPathJarEntry extends PathHandler {
if (!Files.exists(root)) { if (!Files.exists(root)) {
return; return;
} }
try { try (JarFile jarFile = new JarFile(root.toFile())) {
JarFile jarFile = new JarFile(root.toFile());
JarEntry entry; JarEntry entry;
for (Enumeration<JarEntry> e = jarFile.entries(); for (Enumeration<JarEntry> e = jarFile.entries();
e.hasMoreElements(); ) { e.hasMoreElements(); ) {

View File

@ -54,8 +54,7 @@ public class ClassPathJimageEntry extends PathHandler {
if (!Files.exists(root)) { if (!Files.exists(root)) {
return; return;
} }
try { try (ImageReader reader = ImageReader.open(root)) {
ImageReader reader = ImageReader.open(root);
Arrays.stream(reader.getEntryNames()) Arrays.stream(reader.getEntryNames())
.filter(name -> name.endsWith(".class")) .filter(name -> name.endsWith(".class"))
.filter(name -> !name.endsWith("module-info.class")) .filter(name -> !name.endsWith("module-info.class"))

View File

@ -90,6 +90,10 @@ public class CompileTheWorld {
} catch (Throwable t){ } catch (Throwable t){
t.printStackTrace(ERR); t.printStackTrace(ERR);
} finally { } finally {
try {
OUT.close();
} catch (Throwable ignore) {
}
// <clinit> might have started new threads // <clinit> might have started new threads
System.exit(passed ? 0 : 1); System.exit(passed ? 0 : 1);
} }

View File

@ -27,6 +27,7 @@ import jdk.test.lib.Utils;
import jdk.test.lib.process.ProcessTools; import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.Pair; import jdk.test.lib.util.Pair;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -145,11 +146,11 @@ public class CtwRunner {
} }
private Pair<String, Long> getLastClass(Path errFile) { private Pair<String, Long> getLastClass(Path errFile) {
try { try (BufferedReader reader = Files.newBufferedReader(errFile)) {
String line = Files.newBufferedReader(errFile) String line = reader.lines()
.lines()
.filter(IS_CLASS_LINE) .filter(IS_CLASS_LINE)
.reduce((a, b) -> b).orElse(null); .reduce((a, b) -> b)
.orElse(null);
if (line != null) { if (line != null) {
int open = line.indexOf('[') + 1; int open = line.indexOf('[') + 1;
int close = line.indexOf(']'); int close = line.indexOf(']');