Skip to content
Snippets Groups Projects
Commit 30e0321d authored by Alan Bateman's avatar Alan Bateman
Browse files

6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open

Reviewed-by: mchung
parent 0a801a25
Branches
Tags
No related merge requests found
Showing
with 246 additions and 225 deletions
......@@ -196,80 +196,6 @@ java/beans/XMLEncoder/6329581/Test6329581.java generic-all
java/io/BufferedReader/BigMark.java generic-all
java/io/BufferedReader/ReadLineSync.java generic-all
# One of these is leaving "a.ser" file open, windows samevm
java/io/Serializable/duplicateSerialFields/Setup.java generic-all
java/io/Serializable/duplicateSerialFields/Test.java generic-all
# One of these leaving foo.ser open, windows samevm problem
java/io/Serializable/enum/constantSubclasses/Read.java generic-all
java/io/Serializable/enum/constantSubclasses/Write.java generic-all
java/io/Serializable/enum/missingConstant/Read.java generic-all
java/io/Serializable/enum/missingConstant/Write.java generic-all
# This is leaving subtest1.tmp open, windows samevm problem
java/io/Serializable/oldTests/AnnotateClass.java generic-all
# One or more of these leave a piotest* file open, windows samevm
java/io/Serializable/oldTests/ArrayFields.java generic-all
java/io/Serializable/oldTests/ArraysOfArrays.java generic-all
java/io/Serializable/oldTests/BinaryTree.java generic-all
java/io/Serializable/oldTests/CircularList.java generic-all
java/io/Serializable/oldTests/SerializeWithException.java generic-all
java/io/Serializable/oldTests/SimpleArrays.java generic-all
java/io/Serializable/oldTests/WritePrimitive.java generic-all
# Missing close on file 0.ser, windows samevm
java/io/Serializable/enum/badResolve/Read.java generic-all
java/io/Serializable/enum/badResolve/Write.java generic-all
# One of these tests is leaving parents.ser open, windows samevm
java/io/Serializable/parents/EvolvedClass.java generic-all
java/io/Serializable/parents/OriginalClass.java generic-all
# One of these tests is leaving file foo.ser and/or bar.ser open, windows samevm
java/io/Serializable/fieldTypeString/Read.java generic-all
java/io/Serializable/fieldTypeString/Write.java generic-all
# One of these tests is leaving tmp.ser file open, windows samevm
java/io/Serializable/ClassCastExceptionDetail/Read.java generic-all
java/io/Serializable/ClassCastExceptionDetail/Write.java generic-all
java/io/Serializable/GetField/Read.java generic-all
java/io/Serializable/GetField/Read2.java generic-all
java/io/Serializable/GetField/Write.java generic-all
java/io/Serializable/PutField/Read.java generic-all
java/io/Serializable/PutField/Read2.java generic-all
java/io/Serializable/PutField/Write.java generic-all
java/io/Serializable/PutField/Write2.java generic-all
java/io/Serializable/arraySuidConflict/Read.java generic-all
java/io/Serializable/arraySuidConflict/Write.java generic-all
java/io/Serializable/backRefCNFException/Read.java generic-all
java/io/Serializable/backRefCNFException/Write.java generic-all
java/io/Serializable/class/Test.java generic-all
java/io/Serializable/evolution/AddedExternField/ReadAddedField.java generic-all
java/io/Serializable/evolution/AddedExternField/WriteAddedField.java generic-all
java/io/Serializable/evolution/AddedExternField/run.sh generic-all
java/io/Serializable/evolution/AddedField/ReadAddedField.java generic-all
java/io/Serializable/evolution/AddedField/WriteAddedField.java generic-all
java/io/Serializable/evolution/AddedSuperClass/ReadAddedSuperClass.java generic-all
java/io/Serializable/evolution/AddedSuperClass/ReadAddedSuperClass2.java generic-all
java/io/Serializable/evolution/AddedSuperClass/WriteAddedSuperClass.java generic-all
java/io/Serializable/proxy/skipMissing/Read.java generic-all
java/io/Serializable/proxy/skipMissing/Write.java generic-all
java/io/Serializable/readObjectNoData/Read.java generic-all
java/io/Serializable/readObjectNoData/Write.java generic-all
java/io/Serializable/skipWriteObject/Read.java generic-all
java/io/Serializable/skipWriteObject/Write.java generic-all
java/io/Serializable/skippedObjCNFException/Read.java generic-all
java/io/Serializable/skippedObjCNFException/Write.java generic-all
java/io/Serializable/stopCustomDeserialization/Read.java generic-all
java/io/Serializable/stopCustomDeserialization/Write.java generic-all
java/io/Serializable/unresolvedClassDesc/Read.java generic-all
java/io/Serializable/unresolvedClassDesc/Write.java generic-all
java/io/Serializable/unshared/Read.java generic-all
java/io/Serializable/unshared/Write.java generic-all
java/io/Serializable/wrongReturnTypes/Read.java generic-all
java/io/Serializable/wrongReturnTypes/Write.java generic-all
# Windows samevm issues? triggers other tests to fail, missing close() on f.txt?
java/io/DataInputStream/OpsAfterClose.java generic-all
......@@ -323,13 +249,6 @@ java/io/RandomAccessFile/skipBytes/SkipBytes.java generic-all
java/io/readBytes/MemoryLeak.java generic-all
java/io/readBytes/ReadBytesBounds.java generic-all
# Missing close on fields.ser, windows samevm
java/io/Serializable/checkModifiers/CheckModifiers.java generic-all
# Should be othervm, or corrected for samevm, fails with samevm:
java/io/Serializable/auditStreamSubclass/AuditStreamSubclass.java generic-all
java/io/Serializable/proxy/Basic.java generic-all
# Possibly not doing a close() on input.txt, windows samevm issues.
java/io/StreamTokenizer/Comment.java generic-all
......
......@@ -40,9 +40,9 @@ class Gub extends Foo {}
public class Read {
public static void main(String[] args) throws Exception {
ObjectInputStream oin =
new ObjectInputStream(new FileInputStream("tmp.ser"));
FileInputStream in = new FileInputStream("tmp.ser");
try {
ObjectInputStream oin = new ObjectInputStream(in);
oin.readObject();
throw new Error("readObject should not succeed");
} catch (ClassCastException e) {
......@@ -57,6 +57,8 @@ public class Read {
{
throw new Error("ClassNotFoundException message incomplete");
}
} finally {
in.close();
}
}
}
......@@ -26,6 +26,8 @@
* @summary Verify that unauthorized ObjectOutputStream and ObjectInputStream
* cannot be constructed if they override security-sensitive non-final
* methods.
* @build AuditStreamSubclass
* @run main/othervm AuditStreamSubclass
*/
import java.io.*;
......
......@@ -38,13 +38,17 @@ class A implements Serializable {
public class Read {
public static void main(String[] args) throws Exception {
ObjectInputStream oin =
new ObjectInputStream(new FileInputStream("tmp.ser"));
FileInputStream in = new FileInputStream("tmp.ser");
try {
ObjectInputStream oin = new ObjectInputStream(in);
oin.readObject();
try {
oin.readObject();
throw new Error("back reference read succeeded");
} catch (ClassNotFoundException ex) {
}
} finally {
in.close();
}
}
}
......@@ -213,8 +213,8 @@ public class CheckModifiers {
FileOutputStream fos = new FileOutputStream("fields.ser");
try {
ObjectOutputStream oos = new ObjectOutputStream(fos);
System.out.println("Writing obj 1");
oos.writeObject(tc1);
System.out.println("Writing obj 2");
......@@ -223,11 +223,14 @@ public class CheckModifiers {
oos.writeObject(tc3);
System.out.println("Writing obj 4");
oos.writeObject(tc4);
oos.flush();
} finally {
fos.close();
}
FileInputStream fis = new FileInputStream("fields.ser");
try {
ObjectInputStream ois = new ObjectInputStream(fis);
System.out.println("Test modifiers for serialPeristentFields ");
System.out.println("---------------------------------------- ");
System.out.println("Declaration missing final modifier");
......@@ -241,5 +244,8 @@ public class CheckModifiers {
System.out.println();
System.out.println("Declaration as in specification");
ois.readObject();
} finally {
fis.close();
}
}
};
......@@ -42,10 +42,15 @@ public class Read {
* descriptor.
*/
File f = new File(System.getProperty("test.src", "."), "Foo.ser");
new ObjectInputStream(new FileInputStream(f)).readObject();
FileInputStream in = new FileInputStream(f);
try {
new ObjectInputStream(in).readObject();
throw new Error(
"read succeeded for object whose class descriptor has " +
"both SC_SERIALIZABLE and SC_EXTERNALIZABLE flags set");
} finally {
in.close();
}
} catch (InvalidClassException e) {
}
}
......
......@@ -93,8 +93,12 @@ public class ClassDescHooks implements ObjectStreamConstants {
bout = new ByteArrayOutputStream();
foof = new File(System.getProperty("test.src", "."), "Foo.ser");
fin = new FileInputStream(foof);
try {
while (fin.available() > 0)
bout.write(fin.read());
} finally {
fin.close();
}
byte[] buf1 = bout.toByteArray();
bout = new ByteArrayOutputStream();
......@@ -107,11 +111,16 @@ public class ClassDescHooks implements ObjectStreamConstants {
if (! Arrays.equals(buf1, buf2))
throw new Error("Incompatible stream format (write)");
Foo foocopy;
fin = new FileInputStream(foof);
try {
oin = new ObjectInputStream(fin);
Foo foocopy = (Foo) oin.readObject();
foocopy = (Foo) oin.readObject();
if (! foo.equals(foocopy))
throw new Error("Incompatible stream format (read)");
} finally {
fin.close();
}
// make sure write hook not called when old protocol in use
bout = new ByteArrayOutputStream();
......
......@@ -82,18 +82,26 @@ public class Test {
} catch (InvalidClassException e) {
}
FileInputStream in = new FileInputStream("a.ser");
try {
new ObjectInputStream(new FileInputStream("a.ser")).readObject();
ObjectInputStream oin = new ObjectInputStream(in);
oin.readObject();
throw new Error(
"read of A should fail with InvalidClassException");
} catch (InvalidClassException e) {
} finally {
in.close();
}
in = new FileInputStream("b.ser");
try {
new ObjectInputStream(new FileInputStream("b.ser")).readObject();
ObjectInputStream oin = new ObjectInputStream(in);
oin.readObject();
throw new Error(
"read of B should fail with InvalidClassException");
} catch (InvalidClassException e) {
} finally {
in.close();
}
}
}
......@@ -44,13 +44,15 @@ public class Read {
}
static void read(String filename) throws Exception {
ObjectInputStream oin =
new ObjectInputStream(new FileInputStream(filename));
FileInputStream in = new FileInputStream(filename);
try {
ObjectInputStream oin = new ObjectInputStream(in);
Object obj = oin.readObject();
throw new Error("read of " + obj + " should not have succeeded");
} catch (InvalidClassException e) {
System.out.println("caught expected exception " + e);
} finally {
in.close();
}
}
}
......@@ -38,13 +38,17 @@ enum Foo {
public class Read {
public static void main(String[] args) throws Exception {
ObjectInputStream oin =
new ObjectInputStream(new FileInputStream("foo.ser"));
FileInputStream in = new FileInputStream("foo.ser");
try {
ObjectInputStream oin = new ObjectInputStream(in);
for (Foo f : Foo.values()) {
Object obj = oin.readObject();
if (obj != f) {
throw new Error("expected " + f + ", got " + obj);
}
}
} finally {
in.close();
}
}
}
......@@ -33,8 +33,9 @@ enum Foo { foo, bar }
public class Read {
public static void main(String[] args) throws Exception {
ObjectInputStream oin =
new ObjectInputStream(new FileInputStream("foo.ser"));
FileInputStream in = new FileInputStream("foo.ser");
try {
ObjectInputStream oin = new ObjectInputStream(in);
for (Foo f : Foo.values()) {
Object obj = oin.readObject();
if (obj != f) {
......@@ -47,5 +48,8 @@ public class Read {
} catch (InvalidObjectException e) {
System.out.println("caught expected exception: " + e);
}
} finally {
in.close();
}
}
}
......@@ -44,8 +44,9 @@ class Bar implements Serializable {
public class Read {
public static void main(String[] args) throws Exception {
ObjectInputStream oin =
new ObjectInputStream(new FileInputStream("foo.ser"));
FileInputStream in = new FileInputStream("foo.ser");
try {
ObjectInputStream oin = new ObjectInputStream(in);
Foo foo = (Foo) oin.readObject();
if (! foo.obj.equals("foo")) {
throw new Error();
......@@ -55,12 +56,18 @@ public class Read {
throw new Error();
} catch (ClassCastException ex) {
}
} finally {
in.close();
}
oin = new ObjectInputStream(new FileInputStream("bar.ser"));
in = new FileInputStream("bar.ser");
try {
ObjectInputStream oin = new ObjectInputStream(in);
oin.readObject();
throw new Error();
} catch (InvalidClassException ex) {
} finally {
in.close();
}
}
}
......@@ -38,21 +38,31 @@ public class Test {
* serialized String object followed by an illegal handle
*/
File f = new File(base, "negativeHandle.ser");
ObjectInputStream oin = new ObjectInputStream(new FileInputStream(f));
FileInputStream in = new FileInputStream(f);
try {
ObjectInputStream oin = new ObjectInputStream(in);
oin.readObject();
try {
oin.readObject();
throw new Error("negative handle read should not succeed");
} catch (StreamCorruptedException ex) {
}
} finally {
in.close();
}
f = new File(base, "tooHighHandle.ser");
oin = new ObjectInputStream(new FileInputStream(f));
in = new FileInputStream(f);
try {
ObjectInputStream oin = new ObjectInputStream(in);
oin.readObject();
try {
oin.readObject();
throw new Error("too-high handle read should not succeed");
} catch (StreamCorruptedException ex) {
}
} finally {
in.close();
}
}
}
......@@ -68,17 +68,25 @@ public class LongString {
mesgf = new File(System.getProperty("test.src", "."), "mesg.ser");
fin = new FileInputStream(mesgf);
bout = new ByteArrayOutputStream();
try {
while (fin.available() > 0)
bout.write(fin.read());
} finally {
fin.close();
}
byte[] buf2 = bout.toByteArray();
if (! Arrays.equals(buf1, buf2))
throw new Error("incompatible string format (write)");
fin = new FileInputStream(mesgf);
try {
oin = new ObjectInputStream(fin);
String mesgcopy = (String) oin.readObject();
if (! mesg.equals(mesgcopy))
throw new Error("incompatible string format (read)");
} finally {
fin.close();
}
}
}
......@@ -37,15 +37,18 @@ public class AnnotateClass {
"methods \n");
try {
FileOutputStream ostream = new FileOutputStream("subtest1.tmp");
try {
TestOutputStream p = new TestOutputStream(ostream);
p.writeObject(System.out);
p.writeObject(System.err);
p.writeObject(new PrintStream(ostream));
p.flush();
} finally {
ostream.close();
}
FileInputStream istream = new FileInputStream("subtest1.tmp");
try {
TestInputStream q = new TestInputStream(istream);
PrintStream out = (PrintStream)q.readObject();
......@@ -67,6 +70,10 @@ public class AnnotateClass {
"been written/read as null");
throw new Error();
}
} finally {
istream.close();
}
System.err.println("\nTEST PASSED");
} catch (Exception e) {
System.err.print("TEST FAILED: ");
......
......@@ -35,20 +35,22 @@ import java.io.*;
public class ArrayFields {
public static void main (String argv[]) {
public static void main (String argv[]) throws IOException {
System.err.println("\nRegression test for testing of " +
"serialization/deserialization of objects with " +
"fields of array type\n");
FileOutputStream ostream = null;
FileInputStream istream = null;
try {
FileOutputStream ostream = new FileOutputStream("piotest4.tmp");
ostream = new FileOutputStream("piotest4.tmp");
ObjectOutputStream p = new ObjectOutputStream(ostream);
ArrayTest array = new ArrayTest();
p.writeObject(array);
p.flush();
FileInputStream istream = new FileInputStream("piotest4.tmp");
istream = new FileInputStream("piotest4.tmp");
ObjectInputStream q = new ObjectInputStream(istream);
Object obj = null;
......@@ -73,6 +75,9 @@ public class ArrayFields {
System.err.print("TEST FAILED: ");
e.printStackTrace();
throw new Error();
} finally {
if (istream != null) istream.close();
if (ostream != null) ostream.close();
}
}
}
......@@ -31,14 +31,15 @@
import java.io.*;
public class ArraysOfArrays {
public static void main (String argv[]) {
public static void main (String argv[]) throws IOException {
System.err.println("\nRegression test for testing of " +
"serialization/deserialization of objects as " +
"arrays of arrays \n");
FileInputStream istream = null;
FileOutputStream ostream = null;
try {
FileOutputStream ostream = new FileOutputStream("piotest5.tmp");
ostream = new FileOutputStream("piotest5.tmp");
ObjectOutputStream p = new ObjectOutputStream(ostream);
byte b[][] = {{ 0, 1}, {2,3}};
......@@ -207,6 +208,9 @@ public class ArraysOfArrays {
throw new Error();
}
throw new Error();
} finally {
if (istream != null) istream.close();
if (ostream != null) ostream.close();
}
}
}
......@@ -37,18 +37,20 @@ public class BinaryTree {
"with BinaryTree types \n");
try {
BinaryTreeTest base = new BinaryTreeTest(2);
FileOutputStream ostream = new FileOutputStream("piotest3.tmp");
try {
ObjectOutputStream p = new ObjectOutputStream(ostream);
BinaryTreeTest base = new BinaryTreeTest(2);
p.writeObject(null);
p.writeObject(base);
p.flush();
} finally {
ostream.close();
}
FileInputStream istream = new FileInputStream("piotest3.tmp");
try {
ObjectInputStream q = new ObjectInputStream(istream);
Object n = q.readObject();
if (n != null) {
System.err.println("\nnull read as " + n);
......@@ -59,6 +61,10 @@ public class BinaryTree {
"incorrectly.");
throw new Error();
}
} finally {
istream.close();
}
System.err.println("\nTEST PASSED");
} catch (Exception e) {
System.err.print("TEST FAILED: ");
......
......@@ -31,20 +31,22 @@
import java.io.*;
public class CircularList {
public static void main (String argv[]) {
public static void main (String argv[]) throws IOException {
System.err.println("\nRegression test for testing of " +
"serialization/deserialization of " +
"objects with CirculalListType types \n");
FileInputStream istream = null;
FileOutputStream ostream = null;
try {
FileOutputStream ostream = new FileOutputStream("piotest7.tmp");
ostream = new FileOutputStream("piotest7.tmp");
ObjectOutputStream p = new ObjectOutputStream(ostream);
CircularListTest.setup();
p.writeObject(CircularListTest.list);
p.flush();
FileInputStream istream = new FileInputStream("piotest7.tmp");
istream = new FileInputStream("piotest7.tmp");
ObjectInputStream q = new ObjectInputStream(istream);
CircularListTest cv = (CircularListTest)q.readObject();
......@@ -58,6 +60,9 @@ public class CircularList {
System.err.print("TEST FAILED: ");
e.printStackTrace();
throw new Error();
} finally {
if (istream != null) istream.close();
if (ostream != null) ostream.close();
}
}
}
......
......@@ -35,13 +35,14 @@ import java.io.*;
public class SimpleArrays {
public static void main (String argv[]) {
public static void main (String argv[]) throws IOException {
System.err.println("\nRegression test for testing of " +
"serialization/deserialization of objects with Arrays types\n");
FileInputStream istream = null;
FileOutputStream ostream = null;
try {
FileOutputStream ostream = new FileOutputStream("piotest2.tmp");
ostream = new FileOutputStream("piotest2.tmp");
ObjectOutputStream p = new ObjectOutputStream(ostream);
byte b[] = { 0, 1};
......@@ -177,6 +178,9 @@ public class SimpleArrays {
throw new Error();
}
throw new Error();
} finally {
if (istream != null) istream.close();
if (ostream != null) ostream.close();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment