*/
package tests.api.java.io;
-import dalvik.annotation.BrokenTest;
+import dalvik.annotation.AndroidOnly;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
import java.io.NotSerializableException;
import java.io.Serializable;
import java.util.Arrays;
+import java.util.Vector;
+@SuppressWarnings("serial")
@TestTargetClass(Serializable.class)
public class SerializationStressTest1 extends SerializationStressTest {
public void run() {
}
+
+ SpecTestSuperClass() {
+ }
}
- private static class SpecTest extends SpecTestSuperClass implements
- Cloneable, Serializable {
+ private static class SpecTest extends SpecTestSuperClass implements Cloneable, Serializable {
public java.lang.String instVar1;
public static java.lang.String staticVar1;
private void readObject(java.io.ObjectInputStream in)
throws java.io.IOException, ClassNotFoundException {
calledReadObject = true;
- String s = ((String) in.readObject());
+ in.readObject();
}
private void writeObject(java.io.ObjectOutputStream out)
public void readObject(java.io.ObjectInputStream in)
throws java.io.IOException, ClassNotFoundException {
calledReadObject = true;
- String s = ((String) in.readObject());
+ in.readObject();
}
public void writeObject(java.io.ObjectOutputStream out)
private static class MyUnserializableExceptionWhenDumping implements
java.io.Serializable {
private static class MyException extends java.io.IOException {
+ @SuppressWarnings("unused")
private Object notSerializable = new Object();
};
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
boolean passed = false;
Throwable t = null;
try {
- objLoaded = dumpAndReload(objToSave);
+ dumpAndReload(objToSave);
} catch (NotSerializableException ns) {
passed = true;
t = ns;
method = "!Serialization",
args = {}
)
- @BrokenTest("throws IllegalAccessException on Android and InvalidClassException on RI")
public void test_18_14_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
((SpecTest) objLoaded).instVar1.equals(FOO));
} catch (IOException e) {
+ e.printStackTrace();
fail("Exception serializing " + objToSave + "\t->"
+ e.toString());
+
} catch (ClassNotFoundException e) {
fail("ClassNotFoundException reading Object type : "
+ e.getMessage());
method = "!Serialization",
args = {}
)
- @BrokenTest("throws IllegalAccessException on Android and InvalidClassException on RI")
public void test_18_15_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
FieldOrder fieldOrder = new FieldOrder();
objToSave = fieldOrder;
if (DEBUG)
System.out.println("Obj = " + objToSave);
- objLoaded = dumpAndReload(objToSave);
+ dumpAndReload(objToSave);
// This test is only useful for X-loading, so if it managed to
// dump&load, we passed the test
assertTrue(MSG_TEST_FAILED + objToSave, true);
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
objToSave = justWriteObject;
if (DEBUG)
System.out.println("Obj = " + objToSave);
- objLoaded = dumpAndReload(objToSave);
+ dumpAndReload(objToSave);
// Call writeObject on the instance even if it does not define
// readObject
assertTrue(MSG_TEST_FAILED + objToSave,
Object objLoaded;
try {
- java.util.Vector vector = new java.util.Vector(1);
+ java.util.Vector<String> vector = new java.util.Vector<String>(1);
vector.add(FOO);
objToSave = vector;
if (DEBUG)
System.out.println("Obj = " + objToSave);
objLoaded = dumpAndReload(objToSave);
// Has to have the string there
+ @SuppressWarnings("unchecked")
+ java.util.Vector<String> obj = (Vector<String>)objLoaded;
assertTrue(MSG_TEST_FAILED + objToSave, FOO
- .equals(((java.util.Vector) objLoaded).elementAt(0)));
+ .equals(obj.elementAt(0)));
} catch (IOException e) {
fail("IOException serializing " + objToSave + " : "
Object objLoaded;
try {
- java.util.Hashtable hashTable = new java.util.Hashtable(5);
+ java.util.Hashtable<String, String> hashTable = new java.util.Hashtable<String, String>(5);
hashTable.put(FOO, FOO);
objToSave = hashTable;
if (DEBUG)
System.out.println("Obj = " + objToSave);
objLoaded = dumpAndReload(objToSave);
- java.util.Hashtable loadedHashTable = (java.util.Hashtable) objLoaded;
+ @SuppressWarnings("unchecked")
+ java.util.Hashtable<String, String> loadedHashTable = (java.util.Hashtable<String, String>) objLoaded;
// Has to have the key/value there (FOO -> FOO)
assertTrue(MSG_TEST_FAILED + objToSave, FOO.equals(loadedHashTable
.get(FOO)));
method = "!Serialization",
args = {}
)
- @BrokenTest("Needs investigation. fails on RI, succeeds on Android. Maybe a bug in the RI.")
+ @KnownFailure("nested writeReplace is not handled")
public void test_18_28_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
assertTrue(
"Executed multiple levels of replacement (see PR 1F9RNT1), loaded= "
+ objLoaded,
- objLoaded instanceof MultipleClassBasedReplacementWhenDumping.C1);
+ objLoaded instanceof String);
} catch (IOException e) {
fail("IOException serializing " + objToSave + " : "
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
ClassBasedReplacementWhenLoadingViolatesFieldType classBasedReplacementWhenLoadingViolatesFieldType = new ClassBasedReplacementWhenLoadingViolatesFieldType();
objToSave = classBasedReplacementWhenLoadingViolatesFieldType;
if (DEBUG)
System.out.println("Obj = " + objToSave);
- objLoaded = dumpAndReload(objToSave);
+ dumpAndReload(objToSave);
// We cannot gere here, the load replacement must have caused a
// field type violation
fail(
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
MyExceptionWhenDumping1 exceptionWhenDumping = new MyExceptionWhenDumping1();
causedException);
causedException = false;
try {
- objLoaded = reload();
+ reload();
// Although the spec says we should get a WriteAbortedException,
// the serialization format handle an Exception when reading
// primitive data so we get ClassCastException instead
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
MyExceptionWhenDumping2 exceptionWhenDumping = new MyExceptionWhenDumping2();
causedException);
causedException = false;
try {
- objLoaded = reload();
+ reload();
} catch (java.io.WriteAbortedException e) {
causedException = true;
}
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
NonSerializableExceptionWhenDumping nonSerializableExceptionWhenDumping = new NonSerializableExceptionWhenDumping();
causedException);
causedException = false;
try {
- objLoaded = reload();
+ reload();
} catch (java.io.WriteAbortedException e) {
causedException = true;
}
method = "!Serialization",
args = {}
)
- @BrokenTest("succeeds on Android, but fails on RI with MyException being thrown.")
public void test_18_33_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
MyUnserializableExceptionWhenDumping exceptionWhenDumping = new MyUnserializableExceptionWhenDumping();
boolean causedException = false;
try {
dump(objToSave);
- } catch (java.io.StreamCorruptedException e) {
+ } catch (java.io.ObjectStreamException e) {
causedException = true;
}
;
// As the stream is corrupted, reading the stream will have
// undefined results
} catch (IOException e) {
+ e.printStackTrace();
fail("IOException serializing " + objToSave + " : "
+ e.getMessage());
} catch (ClassNotFoundException e) {
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
java.io.IOException ioe = new java.io.IOException();
objToSave = ioe;
if (DEBUG)
System.out.println("Obj = " + objToSave);
- objLoaded = dumpAndReload(objToSave);
+ dumpAndReload(objToSave);
// Has to be able to save/load an exception
assertTrue(MSG_TEST_FAILED + objToSave, true);
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
java.io.IOException ex = new java.io.InvalidClassException(FOO);
objToSave = ex;
if (DEBUG)
System.out.println("Obj = " + objToSave);
- objLoaded = dumpAndReload(objToSave);
+ dumpAndReload(objToSave);
// Has to be able to save/load an exception
assertTrue(MSG_TEST_FAILED + objToSave, true);
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
java.io.IOException ex = new java.io.InvalidObjectException(FOO);
objToSave = ex;
if (DEBUG)
System.out.println("Obj = " + objToSave);
- objLoaded = dumpAndReload(objToSave);
+ dumpAndReload(objToSave);
// Has to be able to save/load an exception
assertTrue(MSG_TEST_FAILED + objToSave, true);
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
java.io.IOException ex = new java.io.NotActiveException(FOO);
objToSave = ex;
if (DEBUG)
System.out.println("Obj = " + objToSave);
- objLoaded = dumpAndReload(objToSave);
+ dumpAndReload(objToSave);
// Has to be able to save/load an exception
assertTrue(MSG_TEST_FAILED + objToSave, true);
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
java.io.IOException ex = new java.io.NotSerializableException(FOO);
objToSave = ex;
if (DEBUG)
System.out.println("Obj = " + objToSave);
- objLoaded = dumpAndReload(objToSave);
+ dumpAndReload(objToSave);
// Has to be able to save/load an exception
assertTrue(MSG_TEST_FAILED + objToSave, true);
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
Object objToSave = null;
- Object objLoaded;
try {
java.io.IOException ex = new java.io.StreamCorruptedException(FOO);
objToSave = ex;
if (DEBUG)
System.out.println("Obj = " + objToSave);
- objLoaded = dumpAndReload(objToSave);
+ dumpAndReload(objToSave);
// Has to be able to save/load an exception
assertTrue(MSG_TEST_FAILED + objToSave, true);