--- old/test/hotspot/jtreg/ProblemList.txt 2017-12-12 16:26:07.378278120 -0800 +++ new/test/hotspot/jtreg/ProblemList.txt 2017-12-12 16:26:06.986263423 -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 ############################################################################# --- old/test/hotspot/jtreg/runtime/appcds/MultiReleaseJars.java 2017-12-12 16:26:08.278311863 -0800 +++ new/test/hotspot/jtreg/runtime/appcds/MultiReleaseJars.java 2017-12-12 16:26:07.878296866 -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: --- old/test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java 2017-12-12 16:26:09.130343806 -0800 +++ new/test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java 2017-12-12 16:26:08.766330159 -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(); } } --- old/test/hotspot/jtreg/runtime/appcds/UseAppCDS.java 2017-12-12 16:26:10.186383398 -0800 +++ new/test/hotspot/jtreg/runtime/appcds/UseAppCDS.java 2017-12-12 16:26:09.794368700 -0800 @@ -108,12 +108,14 @@ public static List toClassNames(String filename) throws IOException { ArrayList 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; } --- old/test/hotspot/jtreg/runtime/appcds/cacheObject/RedefineClassTest.java 2017-12-12 16:26:11.058416091 -0800 +++ new/test/hotspot/jtreg/runtime/appcds/cacheObject/RedefineClassTest.java 2017-12-12 16:26:10.658401094 -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; --- old/test/hotspot/jtreg/runtime/appcds/jvmti/InstrumentationTest.java 2017-12-12 16:26:12.370465281 -0800 +++ new/test/hotspot/jtreg/runtime/appcds/jvmti/InstrumentationTest.java 2017-12-12 16:26:11.530433787 -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); } --- old/test/hotspot/jtreg/runtime/appcds/test-classes/Util.java 2017-12-12 16:26:13.358502323 -0800 +++ new/test/hotspot/jtreg/runtime/appcds/test-classes/Util.java 2017-12-12 16:26:12.954487176 -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; + } } }