8165603: runtime/appcds/UseAppCDS.java: failed to clean up files after test when running with agentvm
Reviewed-by: mseledtsov, dholmes
--- a/test/hotspot/jtreg/ProblemList.txt Wed Dec 06 11:11:16 2017 +0100
+++ b/test/hotspot/jtreg/ProblemList.txt Wed Dec 13 15:37:48 2017 -0800
@@ -77,7 +77,6 @@
# This test is disabled since it will stress NMT and timeout during normal testing
runtime/NMT/MallocStressTest.java 8166548 generic-all
runtime/SharedArchiveFile/DefaultUseWithClient.java 8154204 generic-all
-runtime/AppCDS/UseAppCDS.java 8165603 windows-all
#############################################################################
--- a/test/hotspot/jtreg/runtime/appcds/MultiReleaseJars.java Wed Dec 06 11:11:16 2017 +0100
+++ b/test/hotspot/jtreg/runtime/appcds/MultiReleaseJars.java Wed Dec 13 15:37:48 2017 -0800
@@ -72,13 +72,14 @@
if (contents == null) {
throw new java.lang.RuntimeException("No input for writing to file" + file);
}
- FileOutputStream fos = new FileOutputStream(file);
- PrintStream ps = new PrintStream(fos);
- for (String str : contents) {
- ps.println(str);
+ try (
+ FileOutputStream fos = new FileOutputStream(file);
+ PrintStream ps = new PrintStream(fos)
+ ) {
+ for (String str : contents) {
+ ps.println(str);
+ }
}
- ps.close();
- fos.close();
}
/* version.jar entries and files:
--- a/test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java Wed Dec 06 11:11:16 2017 +0100
+++ b/test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java Wed Dec 13 15:37:48 2017 -0800
@@ -245,11 +245,10 @@
// Copy file with bytes deleted or inserted
// del -- true, deleted, false, inserted
public static void copyFile(File from, File to, boolean del) throws Exception {
- FileChannel inputChannel = null;
- FileChannel outputChannel = null;
- try {
- inputChannel = new FileInputStream(from).getChannel();
- outputChannel = new FileOutputStream(to).getChannel();
+ try (
+ FileChannel inputChannel = new FileInputStream(from).getChannel();
+ FileChannel outputChannel = new FileOutputStream(to).getChannel()
+ ) {
long size = inputChannel.size();
int init_size = getFileHeaderSize(inputChannel);
outputChannel.transferFrom(inputChannel, 0, init_size);
@@ -264,9 +263,6 @@
outputChannel.write(ByteBuffer.wrap(new byte[n]));
outputChannel.transferFrom(inputChannel, init_size + n , size - init_size);
}
- } finally {
- inputChannel.close();
- outputChannel.close();
}
}
--- a/test/hotspot/jtreg/runtime/appcds/UseAppCDS.java Wed Dec 06 11:11:16 2017 +0100
+++ b/test/hotspot/jtreg/runtime/appcds/UseAppCDS.java Wed Dec 13 15:37:48 2017 -0800
@@ -108,12 +108,14 @@
public static List<String> toClassNames(String filename) throws IOException {
ArrayList<String> classes = new ArrayList<>();
- BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
- for (; ; ) {
- String line = br.readLine();
- if (line == null)
- break;
- classes.add(line.replaceAll("/", "."));
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)))) {
+ for (; ; ) {
+ String line = br.readLine();
+ if (line == null) {
+ break;
+ }
+ classes.add(line.replaceAll("/", "."));
+ }
}
return classes;
}
--- a/test/hotspot/jtreg/runtime/appcds/cacheObject/RedefineClassTest.java Wed Dec 06 11:11:16 2017 +0100
+++ b/test/hotspot/jtreg/runtime/appcds/cacheObject/RedefineClassTest.java Wed Dec 13 15:37:48 2017 -0800
@@ -43,7 +43,6 @@
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;
import java.io.File;
-import java.io.FileOutputStream;
import java.util.List;
import jdk.test.lib.Asserts;
import jdk.test.lib.cds.CDSOptions;
--- a/test/hotspot/jtreg/runtime/appcds/jvmti/InstrumentationTest.java Wed Dec 06 11:11:16 2017 +0100
+++ b/test/hotspot/jtreg/runtime/appcds/jvmti/InstrumentationTest.java Wed Dec 13 15:37:48 2017 -0800
@@ -182,9 +182,9 @@
// We use the flagFile to prevent the child process to make progress, until we have
// attached to it.
File f = new File(flagFile);
- FileOutputStream o = new FileOutputStream(f);
- o.write(1);
- o.close();
+ try (FileOutputStream o = new FileOutputStream(f)) {
+ o.write(1);
+ }
if (!f.exists()) {
throw new RuntimeException("Failed to create " + f);
}
--- a/test/hotspot/jtreg/runtime/appcds/test-classes/Util.java Wed Dec 06 11:11:16 2017 +0100
+++ b/test/hotspot/jtreg/runtime/appcds/test-classes/Util.java Wed Dec 13 15:37:48 2017 -0800
@@ -39,7 +39,7 @@
throws FileNotFoundException, IOException, NoSuchMethodException, IllegalAccessException,
InvocationTargetException
{
- DataInputStream dis = new DataInputStream(new FileInputStream(clsFile));
+ try (DataInputStream dis = new DataInputStream(new FileInputStream(clsFile))) {
byte[] buff = new byte[(int)clsFile.length()];
dis.readFully(buff);
replace(buff, fromString, toString);
@@ -57,6 +57,7 @@
System.out.println("Loaded : " + cls);
return cls;
+ }
}
/**
@@ -146,11 +147,10 @@
JarFile jf = new JarFile(jarFile);
JarEntry ent = jf.getJarEntry(className.replace('.', '/') + ".class");
- DataInputStream dis = new DataInputStream(jf.getInputStream(ent));
- byte[] buff = new byte[(int)ent.getSize()];
- dis.readFully(buff);
- dis.close();
-
- return buff;
+ try (DataInputStream dis = new DataInputStream(jf.getInputStream(ent))) {
+ byte[] buff = new byte[(int)ent.getSize()];
+ dis.readFully(buff);
+ return buff;
+ }
}
}