8165603: runtime/appcds/UseAppCDS.java: failed to clean up files after test when running with agentvm

Reviewed-by: mseledtsov, dholmes
This commit is contained in:
Ioi Lam 2017-12-13 15:37:48 -08:00
parent 3c55f378ca
commit 5dd68ed125
7 changed files with 29 additions and 32 deletions

View File

@ -77,7 +77,6 @@ runtime/CompressedOops/UseCompressedOops.java 8079353 generic-all
# 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
#############################################################################

View File

@ -72,13 +72,14 @@ public class MultiReleaseJars {
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:

View File

@ -245,11 +245,10 @@ public class SharedArchiveConsistency {
// 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 @@ public class SharedArchiveConsistency {
outputChannel.write(ByteBuffer.wrap(new byte[n]));
outputChannel.transferFrom(inputChannel, init_size + n , size - init_size);
}
} finally {
inputChannel.close();
outputChannel.close();
}
}

View File

@ -108,12 +108,14 @@ public class UseAppCDS {
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;
}

View File

@ -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;

View File

@ -182,9 +182,9 @@ public class InstrumentationTest {
// 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);
}

View File

@ -39,7 +39,7 @@ public class Util {
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 @@ public class Util {
System.out.println("Loaded : " + cls);
return cls;
}
}
/**
@ -146,11 +147,10 @@ public class Util {
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;
}
}
}