6962419: TEST_BUG: java_io tests fails in samevm mode
Reviewed-by: ohair, sherman
diff --git a/test/java/io/BufferedReader/BigMark.java b/test/java/io/BufferedReader/BigMark.java
index 67b5dd3..fe336a4 100644
--- a/test/java/io/BufferedReader/BigMark.java
+++ b/test/java/io/BufferedReader/BigMark.java
@@ -25,6 +25,8 @@
@summary BufferedReader should throw an OutOfMemoryError when the
read-ahead limit is very large
@bug 6350733
+ @build BigMark
+ @run main/othervm BigMark
*/
import java.io.*;
diff --git a/test/java/io/BufferedReader/ReadLineSync.java b/test/java/io/BufferedReader/ReadLineSync.java
index 1b2dd49..2af83e4 100644
--- a/test/java/io/BufferedReader/ReadLineSync.java
+++ b/test/java/io/BufferedReader/ReadLineSync.java
@@ -46,16 +46,20 @@
BufferedReader reader = new BufferedReader(
new FileReader(f));
- int threadCount = 2;
+ try {
+ int threadCount = 2;
- ExecutorService es = Executors.newFixedThreadPool(threadCount);
+ ExecutorService es = Executors.newFixedThreadPool(threadCount);
- for (int i=0; i < threadCount; i++)
- es.execute(new BufferedReaderConsumer(reader));
+ for (int i=0; i < threadCount; i++)
+ es.execute(new BufferedReaderConsumer(reader));
- // Wait for the tasks to complete
- es.shutdown();
- while (!es.awaitTermination(60, TimeUnit.SECONDS));
+ // Wait for the tasks to complete
+ es.shutdown();
+ while (!es.awaitTermination(60, TimeUnit.SECONDS));
+ } finally {
+ reader.close();
+ }
}
static class BufferedReaderConsumer extends Thread {
diff --git a/test/java/io/DataInputStream/OpsAfterClose.java b/test/java/io/DataInputStream/OpsAfterClose.java
index a0f0fdf..a54926b 100644
--- a/test/java/io/DataInputStream/OpsAfterClose.java
+++ b/test/java/io/DataInputStream/OpsAfterClose.java
@@ -244,13 +244,19 @@
f.deleteOnExit();
FileInputStream fis = new FileInputStream(f);
-
- DataInputStream dis = new DataInputStream(
- new FileInputStream(f));
- if (testDataInputStream(dis)) {
- failed = true;
+ try {
+ DataInputStream dis = new DataInputStream(
+ new FileInputStream(f));
+ try {
+ if (testDataInputStream(dis)) {
+ failed = true;
+ }
+ } finally {
+ dis.close();
+ }
+ } finally {
+ fis.close();
}
-
}
private static boolean testDataInputStream(DataInputStream is)
diff --git a/test/java/io/DataInputStream/ReadFully.java b/test/java/io/DataInputStream/ReadFully.java
index ad94280..53c0ee5 100644
--- a/test/java/io/DataInputStream/ReadFully.java
+++ b/test/java/io/DataInputStream/ReadFully.java
@@ -43,6 +43,7 @@
} catch (IndexOutOfBoundsException ie) {
caughtException = true;
} finally {
+ dis.close();
if (!caughtException)
throw new RuntimeException("Test failed");
}
diff --git a/test/java/io/File/DeleteOnExit.java b/test/java/io/File/DeleteOnExit.java
index 74100ee..b332bf9 100644
--- a/test/java/io/File/DeleteOnExit.java
+++ b/test/java/io/File/DeleteOnExit.java
@@ -48,7 +48,9 @@
public static void main (String args[]) throws Exception{
if (args.length == 0) {
- Runtime.getRuntime().exec(java + " DeleteOnExit -test").waitFor();
+ String cmd = java + " -classpath " + System.getProperty("test.classes")
+ + " DeleteOnExit -test";
+ Runtime.getRuntime().exec(cmd).waitFor();
if (file1.exists() || file2.exists() || file3.exists() ||
dir.exists() || file4.exists() || file5.exists() ||
file6.exists() || file7.exists()) {
diff --git a/test/java/io/File/DeleteOnExitNPE.java b/test/java/io/File/DeleteOnExitNPE.java
index dff7915..50a29c3 100644
--- a/test/java/io/File/DeleteOnExitNPE.java
+++ b/test/java/io/File/DeleteOnExitNPE.java
@@ -45,7 +45,8 @@
public static void runTest() throws Exception {
String cmd = System.getProperty("java.home") + File.separator +
- "bin" + File.separator + "java";
+ "bin" + File.separator + "java" +
+ " -classpath " + System.getProperty("test.classes");
Process process = Runtime.getRuntime().exec(cmd + " DeleteOnExitNPE -test");
BufferedReader isReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader esReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
diff --git a/test/java/io/File/IsHidden.java b/test/java/io/File/IsHidden.java
index a0198d1..e34fcc3 100644
--- a/test/java/io/File/IsHidden.java
+++ b/test/java/io/File/IsHidden.java
@@ -27,7 +27,7 @@
*/
import java.io.*;
-
+import java.nio.file.attribute.DosFileAttributeView;
public class IsHidden {
@@ -41,15 +41,20 @@
System.err.println(path + " ==> " + x);
}
+ private static void setHidden(File f, boolean value) throws IOException {
+ f.toPath().getFileAttributeView(DosFileAttributeView.class).setHidden(value);
+ }
+
private static void testWin32() throws Exception {
File f = new File(dir, "test");
f.deleteOnExit();
f.createNewFile();
- String name = f.getCanonicalPath();
- Process p = Runtime.getRuntime().exec("cmd.exe /c attrib +H " + name);
- p.waitFor();
- ck(name, true);
-
+ setHidden(f, true);
+ try {
+ ck(f.getPath(), true);
+ } finally {
+ setHidden(f, false);
+ }
ck(".foo", false);
ck("foo", false);
}
diff --git a/test/java/io/FileInputStream/LeadingSlash.java b/test/java/io/FileInputStream/LeadingSlash.java
index 7b72be9..3b57243 100644
--- a/test/java/io/FileInputStream/LeadingSlash.java
+++ b/test/java/io/FileInputStream/LeadingSlash.java
@@ -36,8 +36,8 @@
File file = null;
try {
file = File.createTempFile("bug", "4487368");
- new FileInputStream("\\" + file.getPath());
- new FileOutputStream("\\" + file.getPath());
+ new FileInputStream("\\" + file.getPath()).close();
+ new FileOutputStream("\\" + file.getPath()).close();
} finally {
if (file != null)
file.delete();
diff --git a/test/java/io/InputStream/OpsAfterClose.java b/test/java/io/InputStream/OpsAfterClose.java
index 7c64c98..9685782 100644
--- a/test/java/io/InputStream/OpsAfterClose.java
+++ b/test/java/io/InputStream/OpsAfterClose.java
@@ -125,23 +125,35 @@
f.deleteOnExit();
FileInputStream fis = new FileInputStream(f);
- if (testInputStream(fis)) {
- failed = true;
- }
- if (testFileInputStream(fis)) {
- failed = true;
+ try {
+ if (testInputStream(fis)) {
+ failed = true;
+ }
+ if (testFileInputStream(fis)) {
+ failed = true;
+ }
+ } finally {
+ fis.close();
}
BufferedInputStream bs = new BufferedInputStream(
new FileInputStream(f));
- if (testInputStream(bs)) {
- failed = true;
+ try {
+ if (testInputStream(bs)) {
+ failed = true;
+ }
+ } finally {
+ bs.close();
}
DataInputStream dis = new DataInputStream(
new FileInputStream(f));
- if (testInputStream(dis)) {
- failed = true;
+ try {
+ if (testInputStream(dis)) {
+ failed = true;
+ }
+ } finally {
+ dis.close();
}
PushbackInputStream pbis = new PushbackInputStream(
diff --git a/test/java/io/InputStream/ReadParams.java b/test/java/io/InputStream/ReadParams.java
index 36713aa..602445c 100644
--- a/test/java/io/InputStream/ReadParams.java
+++ b/test/java/io/InputStream/ReadParams.java
@@ -137,6 +137,7 @@
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Integer(32));
+ oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
doTest(ois);
doTest1(ois);
diff --git a/test/java/io/InputStreamReader/GrowAfterEOF.java b/test/java/io/InputStreamReader/GrowAfterEOF.java
index 7434401..96bb2a9 100644
--- a/test/java/io/InputStreamReader/GrowAfterEOF.java
+++ b/test/java/io/InputStreamReader/GrowAfterEOF.java
@@ -33,29 +33,36 @@
public static void main(String[] args) throws Exception {
File input = new File(".", "TestEOFInput.txt");
RandomAccessFile rf = new RandomAccessFile(input, "rw");
- BufferedReader r = new BufferedReader
- (new InputStreamReader(new FileInputStream(input)));
+ try {
+ BufferedReader r = new BufferedReader
+ (new InputStreamReader(new FileInputStream(input)));
+ try {
+ // write something
+ rf.writeBytes("a line");
- // write something
- rf.writeBytes("a line");
+ // read till the end of file
+ while (r.readLine() != null);
- // read till the end of file
- while (r.readLine() != null);
+ // append to the end of the file
+ rf.seek(rf.length());
+ rf.writeBytes("new line");
- // append to the end of the file
- rf.seek(rf.length());
- rf.writeBytes("new line");
-
- // now try to read again
- boolean readMore = false;
- while (r.readLine() != null) {
- readMore = true;
- }
- if (!readMore) {
- input.delete();
- throw new Exception("Failed test: unable to read!");
- } else {
- input.delete();
+ // now try to read again
+ boolean readMore = false;
+ while (r.readLine() != null) {
+ readMore = true;
+ }
+ if (!readMore) {
+ input.delete();
+ throw new Exception("Failed test: unable to read!");
+ } else {
+ input.delete();
+ }
+ } finally {
+ r.close();
+ }
+ } finally {
+ rf.close();
}
}
}
diff --git a/test/java/io/ObjectInputStream/ResolveProxyClass.java b/test/java/io/ObjectInputStream/ResolveProxyClass.java
index 59cd3d3..eaea1c3 100644
--- a/test/java/io/ObjectInputStream/ResolveProxyClass.java
+++ b/test/java/io/ObjectInputStream/ResolveProxyClass.java
@@ -79,7 +79,7 @@
* code, and it should be the first loader on the stack when
* ObjectInputStream.resolveProxyClass gets executed.
*/
- ClassLoader expectedLoader = ClassLoader.getSystemClassLoader();
+ ClassLoader expectedLoader = ResolveProxyClass.class.getClassLoader();
TestObjectInputStream in = new TestObjectInputStream();
Class proxyClass = in.resolveProxyClass(
diff --git a/test/java/io/RandomAccessFile/EOF.java b/test/java/io/RandomAccessFile/EOF.java
index aa65fd3..50b48de 100644
--- a/test/java/io/RandomAccessFile/EOF.java
+++ b/test/java/io/RandomAccessFile/EOF.java
@@ -35,12 +35,16 @@
int n;
String dir = System.getProperty("test.src", ".");
RandomAccessFile raf = new RandomAccessFile(new File(dir, "EOF.java"), "r");
- for (;;) {
- n = raf.read(buf, 0, buf.length);
- if (n <= 0) break;
+ try {
+ for (;;) {
+ n = raf.read(buf, 0, buf.length);
+ if (n <= 0) break;
+ }
+ if (n != -1)
+ throw new RuntimeException("Expected -1 for EOF, got " + n);
+ } finally {
+ raf.close();
}
- if (n != -1)
- throw new RuntimeException("Expected -1 for EOF, got " + n);
}
}
diff --git a/test/java/io/RandomAccessFile/ParameterCheck.java b/test/java/io/RandomAccessFile/ParameterCheck.java
index 97319fc..e483929 100644
--- a/test/java/io/RandomAccessFile/ParameterCheck.java
+++ b/test/java/io/RandomAccessFile/ParameterCheck.java
@@ -44,6 +44,7 @@
private static void doTest(String method) throws Exception {
File fn = new File("x.ParameterCheck");
+ RandomAccessFile raf = null;
try {
byte b[] = new byte[32];
@@ -55,7 +56,7 @@
fout.write(i);
}
fout.close();
- RandomAccessFile raf = new RandomAccessFile(fn , "rw");
+ raf = new RandomAccessFile(fn , "rw");
System.err.println("-----------------------------" +
"-----------------------------");
@@ -125,6 +126,8 @@
System.err.println("-----------------------------" +
"-----------------------------");
} finally {
+ if (raf != null)
+ raf.close();
fn.delete();
}
diff --git a/test/java/io/RandomAccessFile/ReadLine.java b/test/java/io/RandomAccessFile/ReadLine.java
index 879926f..1d63ce0 100644
--- a/test/java/io/RandomAccessFile/ReadLine.java
+++ b/test/java/io/RandomAccessFile/ReadLine.java
@@ -33,26 +33,30 @@
public static void main(String args[]) throws Exception {
File fn = new File("x.ReadLine");
RandomAccessFile raf = new RandomAccessFile(fn,"rw");
- String line;
- int ctr = 1;
- String expected;
+ try {
+ String line;
+ int ctr = 1;
+ String expected;
- raf.writeBytes
- ("ln1\rln2\r\nln3\nln4\rln5\r\nln6\n\rln8\r\rln10\n\nln12\r\r\nln14");
- raf.seek(0);
+ raf.writeBytes
+ ("ln1\rln2\r\nln3\nln4\rln5\r\nln6\n\rln8\r\rln10\n\nln12\r\r\nln14");
+ raf.seek(0);
- while ((line=raf.readLine()) != null) {
- if ((ctr == 7) || (ctr == 9) ||
- (ctr == 11) || (ctr == 13)) {
- expected = "";
- } else {
- expected = "ln" + ctr;
+ while ((line=raf.readLine()) != null) {
+ if ((ctr == 7) || (ctr == 9) ||
+ (ctr == 11) || (ctr == 13)) {
+ expected = "";
+ } else {
+ expected = "ln" + ctr;
+ }
+ if (!line.equals(expected)) {
+ throw new Exception("Expected \"" + expected + "\"" +
+ ", read \"" + line + "\"");
+ }
+ ctr++;
}
- if (!line.equals(expected)) {
- throw new Exception("Expected \"" + expected + "\"" +
- ", read \"" + line + "\"");
- }
- ctr++;
+ } finally {
+ raf.close();
}
System.err.println("Successfully completed test!");
}
diff --git a/test/java/io/RandomAccessFile/Seek.java b/test/java/io/RandomAccessFile/Seek.java
index a3f15cd..2a505e5 100644
--- a/test/java/io/RandomAccessFile/Seek.java
+++ b/test/java/io/RandomAccessFile/Seek.java
@@ -44,6 +44,8 @@
throw new Exception
("Should have thrown an IOException when seek offset is < 0");
} catch (IOException e) {
+ } finally {
+ raf.close();
}
}
}
diff --git a/test/java/io/RandomAccessFile/WriteBytesChars.java b/test/java/io/RandomAccessFile/WriteBytesChars.java
index 6803f2b..bbb9494 100644
--- a/test/java/io/RandomAccessFile/WriteBytesChars.java
+++ b/test/java/io/RandomAccessFile/WriteBytesChars.java
@@ -37,8 +37,8 @@
byte[] b = new byte[80];
File fn = new File("x.WriteBytesChars");
- try{
- RandomAccessFile raf = new RandomAccessFile(fn , "rw");;
+ RandomAccessFile raf = new RandomAccessFile(fn , "rw");;
+ try {
for (int i = 0; i < 80; i++) {
buf[i] = 'a';
}
@@ -71,6 +71,7 @@
RuntimeException("RandomAccessFile.writeChars, wrong result");
}
} finally {
+ raf.close();
fn.delete();
}
}
diff --git a/test/java/io/RandomAccessFile/WriteUTF.java b/test/java/io/RandomAccessFile/WriteUTF.java
index ed83127..c3d13e0 100644
--- a/test/java/io/RandomAccessFile/WriteUTF.java
+++ b/test/java/io/RandomAccessFile/WriteUTF.java
@@ -42,8 +42,8 @@
s += s;
System.err.println("String length " + s.length());
+ f = new RandomAccessFile(fn, "rw");
try {
- f = new RandomAccessFile(fn, "rw");
try {
f.writeUTF(s);
}
@@ -53,6 +53,7 @@
throw new RuntimeException("UTFDataFormatException not thrown");
}
finally {
+ f.close();
fn.delete();
}
diff --git a/test/java/io/RandomAccessFile/skipBytes/SkipBytes.java b/test/java/io/RandomAccessFile/skipBytes/SkipBytes.java
index 9c4cf04..0e8723e 100644
--- a/test/java/io/RandomAccessFile/skipBytes/SkipBytes.java
+++ b/test/java/io/RandomAccessFile/skipBytes/SkipBytes.java
@@ -96,14 +96,18 @@
public static void main(String[] args) throws Exception {
RandomAccessFile raf = new RandomAccessFile("input.txt" , "rw");
- int length = (int)raf.length();
+ try {
+ int length = (int)raf.length();
- doTest(raf , 0 , 2*length);
- doTest(raf , 0 , length);
- doTest(raf , 0 , length/2);
- doTest(raf , length/2 , -2);
- doTest(raf , length , 0);
- doTest(raf , 0 , -1);
+ doTest(raf , 0 , 2*length);
+ doTest(raf , 0 , length);
+ doTest(raf , 0 , length/2);
+ doTest(raf , length/2 , -2);
+ doTest(raf , length , 0);
+ doTest(raf , 0 , -1);
+ } finally{
+ raf.close();
+ }
}
diff --git a/test/java/io/Reader/Skip.java b/test/java/io/Reader/Skip.java
index cc4255b..08f627f 100644
--- a/test/java/io/Reader/Skip.java
+++ b/test/java/io/Reader/Skip.java
@@ -35,12 +35,16 @@
File f = new File(System.getProperty("test.src", "."),
"SkipInput.txt");
FileReader fr = new FileReader(f);
- long nchars = 8200;
- long actual = fr.skip(nchars);
+ try {
+ long nchars = 8200;
+ long actual = fr.skip(nchars);
- if (actual > nchars) {
- throw new Exception
- ("Should skip " + nchars + ", but skipped " +actual+" chars");
+ if (actual > nchars) {
+ throw new Exception
+ ("Should skip " + nchars + ", but skipped " +actual+" chars");
+ }
+ } finally {
+ fr.close();
}
}
}
diff --git a/test/java/io/Reader/SkipNegative.java b/test/java/io/Reader/SkipNegative.java
index 17ec0c0..e1aec0c 100644
--- a/test/java/io/Reader/SkipNegative.java
+++ b/test/java/io/Reader/SkipNegative.java
@@ -41,6 +41,8 @@
} catch(IllegalArgumentException e){
// Negative argument caught
return;
+ } finally {
+ fr.close();
}
throw new Exception("Skip should not accept negative values");
}
diff --git a/test/java/io/StreamTokenizer/Comment.java b/test/java/io/StreamTokenizer/Comment.java
index 0563626..f1192fe 100644
--- a/test/java/io/StreamTokenizer/Comment.java
+++ b/test/java/io/StreamTokenizer/Comment.java
@@ -41,40 +41,45 @@
int slashStarComment = 4;
for (int i = 0; i < 8 ; i++) {
- StreamTokenizer st = new StreamTokenizer(new FileReader(f));
+ FileReader reader = new FileReader(f);
+ try {
+ StreamTokenizer st = new StreamTokenizer(reader);
- /* decide the state of this run */
- boolean slashCommentFlag = ((i & slashIsCommentStart) != 0);
- boolean slashSlashCommentFlag = ((i & slashSlashComment) != 0);
- boolean slashStarCommentFlag = ((i & slashStarComment) != 0);
+ /* decide the state of this run */
+ boolean slashCommentFlag = ((i & slashIsCommentStart) != 0);
+ boolean slashSlashCommentFlag = ((i & slashSlashComment) != 0);
+ boolean slashStarCommentFlag = ((i & slashStarComment) != 0);
- /* set the initial state of the tokenizer */
- if (!slashCommentFlag) {
- st.ordinaryChar('/');
- }
- st.slashSlashComments(slashSlashCommentFlag);
- st.slashStarComments(slashStarCommentFlag);
+ /* set the initial state of the tokenizer */
+ if (!slashCommentFlag) {
+ st.ordinaryChar('/');
+ }
+ st.slashSlashComments(slashSlashCommentFlag);
+ st.slashStarComments(slashStarCommentFlag);
- /* now go throgh the input file */
- while(st.nextToken() != StreamTokenizer.TT_EOF)
- {
- String token = st.sval;
- if (token == null) {
- continue;
- } else {
- if ((token.compareTo("Error1") == 0) && slashStarCommentFlag) {
- throw new Exception("Failed to pass one line C comments!");
- }
- if ((token.compareTo("Error2") == 0) && slashStarCommentFlag) {
- throw new Exception("Failed to pass multi line C comments!");
- }
- if ((token.compareTo("Error3") == 0) && slashSlashCommentFlag) {
- throw new Exception("Failed to pass C++ comments!");
- }
- if ((token.compareTo("Error4") == 0) && slashCommentFlag) {
- throw new Exception("Failed to pass / comments!");
+ /* now go throgh the input file */
+ while(st.nextToken() != StreamTokenizer.TT_EOF)
+ {
+ String token = st.sval;
+ if (token == null) {
+ continue;
+ } else {
+ if ((token.compareTo("Error1") == 0) && slashStarCommentFlag) {
+ throw new Exception("Failed to pass one line C comments!");
+ }
+ if ((token.compareTo("Error2") == 0) && slashStarCommentFlag) {
+ throw new Exception("Failed to pass multi line C comments!");
+ }
+ if ((token.compareTo("Error3") == 0) && slashSlashCommentFlag) {
+ throw new Exception("Failed to pass C++ comments!");
+ }
+ if ((token.compareTo("Error4") == 0) && slashCommentFlag) {
+ throw new Exception("Failed to pass / comments!");
+ }
}
}
+ } finally {
+ reader.close();
}
}
}
diff --git a/test/java/io/readBytes/ReadBytesBounds.java b/test/java/io/readBytes/ReadBytesBounds.java
index 4f69e68..eef870b 100644
--- a/test/java/io/readBytes/ReadBytesBounds.java
+++ b/test/java/io/readBytes/ReadBytesBounds.java
@@ -57,24 +57,28 @@
}
public static void main(String argv[]) throws Throwable {
- byte b[] = new byte[32];
- testRead(-1, -1, false);
- testRead(-1, 0, false);
- testRead( 0, -1, false);
- testRead( 0, 33, false);
- testRead(33, 0, false);
- testRead(33, 4, false);
- testRead( 0, 32, true);
- testRead(32, 0, true);
- testRead(32, 4, false);
- testRead( 4, 16, true);
- testRead( 1, 31, true);
- testRead( 0, 0, true);
- testRead(31, Integer.MAX_VALUE, false);
- testRead( 0, Integer.MAX_VALUE, false);
- testRead(-1, Integer.MAX_VALUE, false);
- testRead(-4, Integer.MIN_VALUE, false);
- testRead( 0, Integer.MIN_VALUE, false);
+ try {
+ testRead(-1, -1, false);
+ testRead(-1, 0, false);
+ testRead( 0, -1, false);
+ testRead( 0, 33, false);
+ testRead(33, 0, false);
+ testRead(33, 4, false);
+ testRead( 0, 32, true);
+ testRead(32, 0, true);
+ testRead(32, 4, false);
+ testRead( 4, 16, true);
+ testRead( 1, 31, true);
+ testRead( 0, 0, true);
+ testRead(31, Integer.MAX_VALUE, false);
+ testRead( 0, Integer.MAX_VALUE, false);
+ testRead(-1, Integer.MAX_VALUE, false);
+ testRead(-4, Integer.MIN_VALUE, false);
+ testRead( 0, Integer.MIN_VALUE, false);
+ } finally {
+ fis.close();
+ raf.close();
+ }
}
static void testRead(int off, int len, boolean expected) throws Throwable {