SerializationStressTest2.java revision 561ee011997c6c2f1befbfaa9d5f0a99771c1d63
1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package org.apache.harmony.luni.tests.java.io;
19
20import java.io.ByteArrayInputStream;
21import java.io.ByteArrayOutputStream;
22import java.io.DataOutputStream;
23import java.io.IOException;
24import java.io.InvalidClassException;
25import java.io.NotActiveException;
26import java.io.ObjectInputStream;
27import java.io.ObjectOutputStream;
28import java.io.ObjectStreamClass;
29import java.io.ObjectStreamConstants;
30import java.io.ObjectStreamField;
31import java.io.OptionalDataException;
32import java.io.Serializable;
33import java.util.ArrayList;
34import java.util.Arrays;
35import java.util.Date;
36import java.util.Locale;
37
38
39@SuppressWarnings( { "serial", "unused" })
40public class SerializationStressTest2 extends SerializationStressTest {
41
42	private static class ReadWriteObjectAndPrimitiveData implements
43			java.io.Serializable {
44		transient long milliseconds;
45
46		public boolean calledWriteObject = false;
47
48		public boolean calledReadObject = false;
49
50		public ReadWriteObjectAndPrimitiveData() {
51			super();
52		}
53
54		private void readObject(java.io.ObjectInputStream in)
55				throws java.io.IOException, ClassNotFoundException {
56			in.defaultReadObject();
57			// This *has* to come after the call to defaultReadObject or the
58			// value from the stream will override
59			calledReadObject = true;
60			milliseconds = in.readLong();
61		}
62
63		private void writeObject(java.io.ObjectOutputStream out)
64				throws java.io.IOException {
65			calledWriteObject = true;
66			out.defaultWriteObject();
67			out.writeLong(milliseconds);
68		}
69	}
70
71	// What happens if a class defines serialPersistentFields that do not match
72	// real fields but does not override read/writeObject
73	private static class WithUnmatchingSerialPersistentFields implements
74			java.io.Serializable {
75		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
76				"value", String.class) };
77
78		public int anInstanceVar = 5;
79
80		public WithUnmatchingSerialPersistentFields() {
81			super();
82		}
83	}
84
85	// What happens if a class defines serialPersistentFields which match actual
86	// fields
87	private static class WithMatchingSerialPersistentFields implements
88			java.io.Serializable {
89		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
90				"anInstanceVar", String.class) };
91
92		public String anInstanceVar = FOO + FOO;
93
94		public WithMatchingSerialPersistentFields() {
95			super();
96		}
97	}
98
99	// Tests the oficial behavior for serialPersistentFields
100	private static class SerialPersistentFields implements java.io.Serializable {
101		private static final String SIMULATED_FIELD_NAME = "text";
102
103		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
104				SIMULATED_FIELD_NAME, String.class) };
105
106		public int anInstanceVar = 5;
107
108		public SerialPersistentFields() {
109			super();
110		}
111
112		private void readObject(java.io.ObjectInputStream in)
113				throws java.io.IOException, ClassNotFoundException {
114			ObjectInputStream.GetField fields = in.readFields();
115			anInstanceVar = Integer.parseInt((String) fields.get(
116					SIMULATED_FIELD_NAME, "-5"));
117		}
118
119		private void writeObject(java.io.ObjectOutputStream out)
120				throws java.io.IOException, ClassNotFoundException {
121			ObjectOutputStream.PutField fields = out.putFields();
122			fields.put(SIMULATED_FIELD_NAME, Integer.toString(anInstanceVar));
123			out.writeFields();
124		}
125	}
126
127	// Tests the behavior for serialPersistentFields when no fields are actually
128	// set
129	private static class WriteFieldsWithoutFetchingPutFields implements
130			java.io.Serializable {
131		private static final String SIMULATED_FIELD_NAME = "text";
132
133		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
134				SIMULATED_FIELD_NAME, String.class) };
135
136		public int anInstanceVar = 5;
137
138		public WriteFieldsWithoutFetchingPutFields() {
139			super();
140		}
141
142		private void readObject(java.io.ObjectInputStream in)
143				throws java.io.IOException, ClassNotFoundException {
144			ObjectInputStream.GetField fields = in.readFields();
145		}
146
147		private void writeObject(java.io.ObjectOutputStream out)
148				throws java.io.IOException, ClassNotFoundException {
149			out.writeFields();
150		}
151	}
152
153	// Tests what happens if one asks for PutField/getField when the class does
154	// not declare one
155	private static class SerialPersistentFieldsWithoutField implements
156			java.io.Serializable {
157		public int anInstanceVar = 5;
158
159		public SerialPersistentFieldsWithoutField() {
160			super();
161		}
162
163		private void readObject(java.io.ObjectInputStream in)
164				throws java.io.IOException, ClassNotFoundException {
165			ObjectInputStream.GetField fields = in.readFields();
166		}
167
168		private void writeObject(java.io.ObjectOutputStream out)
169				throws java.io.IOException, ClassNotFoundException {
170			ObjectOutputStream.PutField fields = out.putFields();
171			out.writeFields();
172		}
173	}
174
175	// -----------------------------------------------------------------------------------
176
177	// writeObject writes extra primitive types and objects which readObject
178	// does not consume. Have to make sure we can load object properly AND
179	// object after it (to show the extra byte[] is consumed)
180	private static class OptionalDataNotRead implements java.io.Serializable {
181		private int field1, field2;
182
183		public OptionalDataNotRead() {
184		}
185
186		private static final ObjectStreamField[] serialPersistentFields = {
187				new ObjectStreamField("field1", Integer.TYPE),
188				new ObjectStreamField("field2", Integer.TYPE),
189				new ObjectStreamField("monthLength", byte[].class), };
190
191		private void writeObject(ObjectOutputStream stream) throws IOException {
192			ObjectOutputStream.PutField fields = stream.putFields();
193			fields.put("field1", 1);
194			fields.put("field2", 2);
195			fields.put("monthLength", new byte[] { 7, 8, 9 });
196			stream.writeFields();
197			stream.writeInt(4);
198			byte[] values = new byte[4];
199			values[0] = (byte) 16;
200			values[1] = (byte) 17;
201			values[2] = (byte) 18;
202			values[3] = (byte) 19;
203			stream.writeObject(values);
204		}
205
206		private void readObject(ObjectInputStream stream) throws IOException,
207				ClassNotFoundException {
208			ObjectInputStream.GetField fields = stream.readFields();
209			field1 = fields.get("field1", 0);
210			field2 = fields.get("field1", 0);
211		}
212	}
213
214	// -----------------------------------------------------------------------------------
215	private static class NestedPutField implements java.io.Serializable {
216		public OptionalDataNotRead field1;
217
218		public NestedPutField() {
219		}
220
221		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
222				"field1", OptionalDataNotRead.class), };
223
224		private void writeObject(ObjectOutputStream stream) throws IOException {
225			ObjectOutputStream.PutField fields = stream.putFields();
226			fields.put("field1", new OptionalDataNotRead());
227			stream.writeFields();
228		}
229
230		private void readObject(ObjectInputStream stream) throws IOException,
231				ClassNotFoundException {
232			ObjectInputStream.GetField fields = stream.readFields();
233			field1 = (OptionalDataNotRead) fields.get("field1", null);
234		}
235	}
236
237	// -----------------------------------------------------------------------------------
238
239	// This one tests stream-based replacement when dumping
240	private static class StreamBasedReplacementWhenDumping extends
241			java.io.ObjectOutputStream {
242		public boolean calledArrayReplacement = false;
243
244		public boolean calledStringReplacement = false;
245
246		public boolean calledClassReplacement = false;
247
248		public boolean calledObjectStreamClassReplacement = false;
249
250		public StreamBasedReplacementWhenDumping(java.io.OutputStream output)
251				throws java.io.IOException {
252			super(output);
253			enableReplaceObject(true);
254		}
255
256		protected Object replaceObject(Object obj) throws IOException {
257			Class objClass = obj.getClass();
258			if (objClass == String.class)
259				calledStringReplacement = true;
260
261			if (objClass == Class.class)
262				calledClassReplacement = true;
263
264			if (objClass == ObjectStreamClass.class)
265				calledObjectStreamClassReplacement = true;
266
267			if (objClass.isArray())
268				calledArrayReplacement = true;
269
270			return obj;
271		}
272	}
273
274	// -----------------------------------------------------------------------------------
275
276	private static class ArrayOfSerializable implements Serializable {
277		private Serializable[] testField = null;
278
279		public ArrayOfSerializable() {
280			testField = new Serializable[2];
281			testField[0] = "Hi";
282			testField[1] = "there!";
283		}
284	}
285
286	// -----------------------------------------------------------------------------------
287
288	private static class ClassSubClassTest0 extends java.lang.Object implements
289			java.io.Serializable {
290		String stringVar;
291
292		public ClassSubClassTest0(String init) {
293			stringVar = init;
294		}
295	}
296
297	private static class ClassSubClassTest1 extends ClassSubClassTest0 {
298		String subStringVar;
299
300		public ClassSubClassTest1(String superString, String subString) {
301			super(superString);
302			subStringVar = subString;
303		}
304
305		public boolean equals(Object obj) {
306			if (obj == null)
307				return false;
308			if (!(obj instanceof ClassSubClassTest1))
309				return false;
310
311			ClassSubClassTest1 inst = (ClassSubClassTest1) obj;
312			return inst.subStringVar.equals(this.subStringVar)
313					&& inst.stringVar.equals(this.stringVar);
314		}
315	}
316
317	// -----------------------------------------------------------------------------------
318	private static class ConstructorTestA {
319		public String instVar_classA;
320
321		public final static String ConstrA = "Init in Constructor Class A";
322
323		public final static String ConstrB = "Init in Constructor Class B";
324
325		public final static String ConstrC = "Init in Constructor Class C";
326
327		public final static String ChangedC = "Changed before Serialize - Class C";
328
329		public ConstructorTestA() {
330			instVar_classA = ConstrA;
331		}
332	}
333
334	private static class ConstructorTestB extends ConstructorTestA implements
335			java.io.Serializable {
336		public String instVar_classB;
337
338		public ConstructorTestB() {
339			instVar_classA = ConstrB;
340			instVar_classB = ConstrB;
341		}
342	}
343
344	private static class ConstructorTestC extends ConstructorTestB {
345		public String instVar_classC;
346
347		public ConstructorTestC() {
348			instVar_classA = ConstrC;
349			instVar_classB = ConstrC;
350			instVar_classC = ConstrC;
351		}
352
353		public boolean verify(Object obj) {
354			if (obj == null)
355				return false;
356			if (!(obj instanceof ConstructorTestC))
357				return false;
358
359			ConstructorTestC inst = (ConstructorTestC) obj;
360			return inst.instVar_classC.equals(this.instVar_classC)
361					&& inst.instVar_classB.equals(this.instVar_classB)
362					&& inst.instVar_classA.equals(ConstrA);
363		}
364	}
365
366	// -----------------------------------------------------------------------------------
367	private static class HashCodeTest implements java.io.Serializable {
368		private boolean serializationUsesHashCode = false;
369
370		public int hashCode() {
371			serializationUsesHashCode = true;
372			return super.hashCode();
373		}
374	}
375
376	// -----------------------------------------------------------------------------------
377	private static class InitializerFieldsTest implements java.io.Serializable {
378		public java.lang.String toBeSerialized;
379
380		public static java.lang.String toBeNotSerialized;
381
382		public static java.lang.String toBeNotSerialized2;
383
384		{
385			toBeSerialized = "NonStaticInitialValue";
386		}
387
388		static {
389			toBeNotSerialized = "StaticInitialValue";
390			toBeNotSerialized2 = new String(toBeNotSerialized);
391		}
392
393		public boolean equals(Object obj) {
394			/*
395			 * This method is not answering it the objs is equal. It is
396			 * answering if the vars have the value that it have to have after
397			 * dumping and loading
398			 */
399
400			if (obj == null)
401				return false;
402			if (!(obj instanceof InitializerFieldsTest))
403				return false;
404
405			InitializerFieldsTest inst = (InitializerFieldsTest) obj;
406			return inst.toBeSerialized.equals(this.toBeSerialized)
407					&& InitializerFieldsTest.toBeNotSerialized.equals(toBeNotSerialized2);
408		}
409	}
410
411	private static class InitializerFieldsTest2 implements java.io.Serializable {
412		public java.lang.String toBeSerialized;
413
414		public static java.lang.String toBeNotSerialized;
415
416		public static java.lang.String toBeNotSerialized2;
417
418		{
419			toBeSerialized = "NonStaticInitialValue";
420		}
421
422		public java.lang.String toBeSerialized3;
423
424		public java.lang.String toBeSerialized4;
425		static {
426			toBeNotSerialized = "StaticInitialValue";
427			toBeNotSerialized2 = new String(toBeNotSerialized);
428		}
429
430		public java.lang.String toBeSerialized5;
431
432		public boolean equals(Object obj) {
433			/*
434			 * This method is not answering it the objs is equal. It is
435			 * answering if the vars have the value that it have to have after
436			 * dumping and loading
437			 */
438
439			if (obj == null)
440				return false;
441			if (!(obj instanceof InitializerFieldsTest2))
442				return false;
443
444			InitializerFieldsTest2 inst = (InitializerFieldsTest2) obj;
445			return inst.toBeSerialized.equals(this.toBeSerialized)
446					&& inst.toBeSerialized3.equals(this.toBeSerialized3)
447					&& inst.toBeSerialized4.equals(this.toBeSerialized4)
448					&& inst.toBeSerialized5.equals(this.toBeSerialized5)
449					&& InitializerFieldsTest2.toBeNotSerialized.equals(toBeNotSerialized2);
450		}
451	}
452
453	private static class InitializerFieldsTest3 extends InitializerFieldsTest2
454			implements java.io.Serializable {
455		public java.lang.String sub_toBeSerialized;
456
457		public static java.lang.String sub_toBeNotSerialized;
458
459		public static java.lang.String sub_toBeNotSerialized2;
460
461		{
462			sub_toBeSerialized = "NonStaticInitialValue";
463		}
464
465		public java.lang.String sub_toBeSerialized3;
466
467		public java.lang.String sub_toBeSerialized4;
468		static {
469			sub_toBeNotSerialized = "StaticInitialValue";
470			sub_toBeNotSerialized2 = new String(sub_toBeNotSerialized);
471		}
472
473		public java.lang.String sub_toBeSerialized5;
474
475		public boolean equals(Object obj) {
476			/*
477			 * This method is not answering it the objs is equal. It is
478			 * answering if the vars have the value that it have to have after
479			 * dumping and loading
480			 */
481
482			if (!super.equals(obj))
483				return false;
484			if (!(obj instanceof InitializerFieldsTest3))
485				return false;
486
487			InitializerFieldsTest3 inst = (InitializerFieldsTest3) obj;
488			return inst.sub_toBeSerialized.equals(this.sub_toBeSerialized)
489					&& inst.sub_toBeSerialized3
490							.equals(this.sub_toBeSerialized3)
491					&& inst.sub_toBeSerialized4
492							.equals(this.sub_toBeSerialized4)
493					&& inst.sub_toBeSerialized5
494							.equals(this.sub_toBeSerialized5)
495					&& InitializerFieldsTest3.sub_toBeNotSerialized
496							.equals(sub_toBeNotSerialized2);
497		}
498	}
499
500	// -----------------------------------------------------------------------------------
501	private static class DeepNesting implements java.io.Serializable {
502		public float id;
503
504		public DeepNesting next;
505
506		public boolean dump;
507
508		public boolean load;
509
510		public DeepNesting(float id) {
511			this.id = id;
512			next = null;
513			dump = false;
514			load = false;
515		}
516
517		public DeepNesting(int howMany) {
518			DeepNesting prev = new DeepNesting(0.0F);
519			next(prev);
520			for (int i = 1; i < howMany; i++) {
521				prev = prev.next(new DeepNesting(i * 1.0F));
522			}
523		}
524
525		public boolean equals(Object obj) {
526			if (obj == null)
527				return false;
528			if (!(obj instanceof DeepNesting))
529				return false;
530
531			DeepNesting inst = (DeepNesting) obj;
532			if (inst.dump != this.dump || inst.load != this.load)
533				return false;
534
535			if (inst.next == null || this.next == null)
536				return inst.next == this.next; // both null
537			return this.next.equals(inst.next);
538		}
539
540		public DeepNesting next(DeepNesting ivt) {
541			next = ivt;
542			return ivt;
543		}
544	}
545
546	// -----------------------------------------------------------------------------------
547	private static class DeepNestingWithWriteObject implements
548			java.io.Serializable {
549		public float id;
550
551		public DeepNestingWithWriteObject next;
552
553		public boolean dump;
554
555		public boolean load;
556
557		public DeepNestingWithWriteObject(float id) {
558			this.id = id;
559			next = null;
560			dump = false;
561			load = false;
562		}
563
564		public DeepNestingWithWriteObject(int howMany) {
565			DeepNestingWithWriteObject prev = new DeepNestingWithWriteObject(
566					0.0F);
567			next(prev);
568			for (int i = 1; i < howMany; i++) {
569				prev = prev.next(new DeepNestingWithWriteObject(i * 1.0F));
570			}
571		}
572
573		public boolean equals(Object obj) {
574			if (obj == null)
575				return false;
576			if (!(obj instanceof DeepNestingWithWriteObject))
577				return false;
578
579			DeepNestingWithWriteObject inst = (DeepNestingWithWriteObject) obj;
580			if (inst.dump != this.dump || inst.load != this.load)
581				return false;
582
583			if (inst.next == null || this.next == null)
584				return inst.next == this.next; // both null;
585			return this.next.equals(inst.next);
586		}
587
588		public DeepNestingWithWriteObject next(DeepNestingWithWriteObject ivt) {
589			next = ivt;
590			return ivt;
591		}
592
593		private void writeObject(java.io.ObjectOutputStream s)
594				throws IOException {
595			s.defaultWriteObject();
596		}
597
598		private void readObject(java.io.ObjectInputStream s)
599				throws IOException, ClassNotFoundException {
600			s.defaultReadObject();
601		}
602	}
603
604	// -----------------------------------------------------------------------------------
605	static class NonPublicClassTest extends java.lang.Object implements
606			java.io.Serializable {
607		int field = 1;
608
609		public NonPublicClassTest() {
610			field = 10;
611		}
612
613		public boolean equals(Object o) {
614			if (o instanceof NonPublicClassTest)
615				return field == ((NonPublicClassTest) o).field;
616			return false;
617		}
618
619		public void x10() {
620			field *= 10;
621		}
622	}
623
624	// -----------------------------------------------------------------------------------
625	private static class SameInstVarNameSuperClass {
626		private int foo;
627
628		public SameInstVarNameSuperClass() {
629			super();
630		}
631
632		public SameInstVarNameSuperClass(int fooValue) {
633			foo = fooValue;
634		}
635
636		public String toString() {
637			return "foo = " + foo;
638		}
639	}
640
641	private static class SameInstVarNameSubClass extends
642			SameInstVarNameSuperClass implements java.io.Serializable {
643		protected int foo;
644
645		public SameInstVarNameSubClass() {
646			super();
647		}
648
649		public SameInstVarNameSubClass(int fooValue) {
650			super(-fooValue);
651			foo = fooValue;
652		}
653	}
654
655	// -----------------------------------------------------------------------------------
656	private static class SInterfaceTest implements java.io.Serializable {
657		public static int staticVar = 5;
658
659		public transient int[] transVar = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
660
661		public int instanceVar = 7;
662
663		public boolean equals(Object obj) {
664			if (obj == null)
665				return false;
666			if (!(obj instanceof SInterfaceTest))
667				return false;
668
669			SInterfaceTest inst = (SInterfaceTest) obj;
670			if (this.instanceVar != inst.instanceVar)
671				return false;
672			if (inst.transVar == null || this.transVar == null)
673				return inst.transVar == this.transVar; // both null
674			for (int i = 0; i < transVar.length; i++)
675				if (inst.transVar[i] != this.transVar[i])
676					return false;
677			return true;
678		}
679
680		private void readObject(java.io.ObjectInputStream s)
681				throws IOException, ClassNotFoundException {
682			Object arr;
683			s.defaultReadObject();
684			arr = s.readObject();
685			transVar = (int[]) arr;
686		}
687
688		private void writeObject(java.io.ObjectOutputStream s)
689				throws IOException {
690			s.defaultWriteObject();
691			s.writeObject(transVar);
692		}
693
694		public void x10() {
695			for (int i = 0; i < transVar.length; i++)
696				transVar[i] = transVar[i] * 10;
697			instanceVar = instanceVar * 10;
698		}
699	}
700
701	// -----------------------------------------------------------------------------------
702	private static class SInterfaceTest2 extends SInterfaceTest {
703		private void readObject(java.io.ObjectInputStream s)
704				throws IOException, ClassNotFoundException {
705			Object arr;
706			instanceVar = s.readInt();
707			arr = s.readObject();
708			transVar = (int[]) arr;
709		}
710
711		private void writeObject(java.io.ObjectOutputStream s)
712				throws IOException {
713			s.writeInt(instanceVar);
714			s.writeObject(transVar);
715		}
716	}
717
718	// -----------------------------------------------------------------------------------
719	private static class SuperclassTest extends java.lang.Object implements
720			java.io.Serializable {
721		int superfield = 1;
722
723		public SuperclassTest() {
724			superfield = 10;
725		}
726
727		public boolean equals(Object o) {
728			if (o.getClass() == this.getClass())
729				return superfield == ((SuperclassTest) o).superfield;
730			return false;
731		}
732
733		private void readObject(java.io.ObjectInputStream s)
734				throws IOException, ClassNotFoundException {
735			superfield = s.readInt();
736		}
737
738		private void writeObject(java.io.ObjectOutputStream s)
739				throws IOException {
740			s.writeInt(superfield);
741		}
742
743		public void x10() {
744			superfield *= 10;
745		}
746	}
747
748	// -----------------------------------------------------------------------------------
749	private static class SuperclassTest2 extends SuperclassTest {
750		int subfield = 5;
751
752		public SuperclassTest2() {
753			subfield = 50;
754		}
755
756		public boolean equals(Object o) {
757			if (o instanceof SuperclassTest2)
758				if (subfield == ((SuperclassTest2) o).subfield)
759					return super.equals(o);
760			return false;
761		}
762
763		private void readObject(java.io.ObjectInputStream s)
764				throws IOException, ClassNotFoundException {
765			subfield = s.readInt();
766		}
767
768		private void writeObject(java.io.ObjectOutputStream s)
769				throws IOException {
770			s.writeInt(subfield);
771		}
772
773		public void x10() {
774			subfield *= 10;
775			super.x10();
776		}
777	}
778
779	// -----------------------------------------------------------------------------------
780	private static class SyntheticFieldTest implements java.io.Serializable {
781		public boolean equals(Object obj) {
782			/*
783			 * This method is not answering it the objs is equal. It is
784			 * answering if the vars have the value that it have to have after
785			 * dumping and loading
786			 */
787			if (obj == null)
788				return false;
789			return obj instanceof SyntheticFieldTest;
790		}
791
792		public int hashCode() {
793			// Insert code to generate a hash code for the receiver here.
794			// This implementation forwards the message to super. You may
795			// replace or supplement this.
796			// NOTE: if two objects are equal (equals Object) returns true) they
797			// must have the same hash code
798			Class[] c = { String.class }; // *** synthetic field
799			return super.hashCode();
800		}
801	}
802
803	public SerializationStressTest2(String name) {
804		super(name);
805	}
806
807	public void test_18_41_writeObject() {
808		// Test for method void
809		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
810
811		Object objToSave = null;
812		Object objLoaded;
813
814		try {
815			java.io.IOException ex = new java.io.WriteAbortedException(FOO,
816					null);
817			objToSave = ex;
818			if (DEBUG)
819				System.out.println("Obj = " + objToSave);
820			objLoaded = dumpAndReload(objToSave);
821			// Has to be able to save/load an exception
822			assertTrue(MSG_TEST_FAILED + objToSave, true);
823
824		} catch (IOException e) {
825			fail("IOException serializing " + objToSave + " : "
826					+ e.getMessage());
827		} catch (ClassNotFoundException e) {
828			fail("ClassNotFoundException reading Object type : "
829					+ e.getMessage());
830		} catch (Error err) {
831			System.out.println("Error when obj = " + objToSave);
832			// err.printStackTrace();
833			throw err;
834		}
835	}
836
837	public void test_18_42_writeObject() {
838		// Test for method void
839		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
840
841		Object objToSave = null;
842		Object objLoaded;
843
844		try {
845			WithUnmatchingSerialPersistentFields spf = new WithUnmatchingSerialPersistentFields();
846			objToSave = spf;
847			if (DEBUG)
848				System.out.println("Obj = " + objToSave);
849			boolean causedException = false;
850			try {
851				objLoaded = dumpAndReload(objToSave);
852			} catch (InvalidClassException ce) {
853				causedException = true;
854			}
855			assertTrue("serialPersistentFields do not match real fields",
856					causedException);
857
858		} catch (IOException e) {
859			fail("IOException serializing " + objToSave + " : "
860					+ e.getMessage());
861		} catch (ClassNotFoundException e) {
862			fail("ClassNotFoundException reading Object type : "
863					+ e.getMessage());
864		} catch (Error err) {
865			System.out.println("Error when obj = " + objToSave);
866			// err.printStackTrace();
867			throw err;
868		}
869	}
870
871	public void test_18_43_writeObject() {
872		// Test for method void
873		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
874
875		Object objToSave = null;
876		Object objLoaded;
877
878		try {
879			WithMatchingSerialPersistentFields spf = new WithMatchingSerialPersistentFields();
880			spf.anInstanceVar = FOO;
881			objToSave = spf;
882			if (DEBUG)
883				System.out.println("Obj = " + objToSave);
884			objLoaded = dumpAndReload(objToSave);
885			assertTrue(
886					"serialPersistentFields do not work properly in this implementation",
887					FOO
888							.equals(((WithMatchingSerialPersistentFields) objLoaded).anInstanceVar));
889
890		} catch (IOException e) {
891			fail("IOException serializing " + objToSave + " : "
892					+ e.getMessage());
893		} catch (ClassNotFoundException e) {
894			fail("ClassNotFoundException reading Object type : "
895					+ e.getMessage());
896		} catch (Error err) {
897			System.out.println("Error when obj = " + objToSave);
898			// err.printStackTrace();
899			throw err;
900		}
901	}
902
903	public void test_18_44_writeObject() {
904		// Test for method void
905		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
906
907		Object objToSave = null;
908		Object objLoaded;
909
910		try {
911			SerialPersistentFields spf = new SerialPersistentFields();
912			final int CONST = -500;
913			spf.anInstanceVar = CONST;
914			objToSave = spf;
915			if (DEBUG)
916				System.out.println("Obj = " + objToSave);
917			objLoaded = dumpAndReload(objToSave);
918			assertTrue(
919					"serialPersistentFields do not work properly in this implementation",
920					((SerialPersistentFields) objLoaded).anInstanceVar == CONST);
921
922		} catch (IOException e) {
923			fail("IOException serializing " + objToSave + " : "
924					+ e.getMessage());
925		} catch (ClassNotFoundException e) {
926			fail("ClassNotFoundException reading Object type : "
927					+ e.getMessage());
928		} catch (Error err) {
929			System.out.println("Error when obj = " + objToSave);
930			// err.printStackTrace();
931			throw err;
932		}
933	}
934
935	public void test_18_45_writeObject() {
936		// Test for method void
937		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
938
939		Object objToSave = null;
940		Object objLoaded;
941
942		try {
943			WriteFieldsWithoutFetchingPutFields spf = new WriteFieldsWithoutFetchingPutFields();
944			objToSave = spf;
945			if (DEBUG)
946				System.out.println("Obj = " + objToSave);
947			boolean causedException = false;
948			try {
949				objLoaded = dumpAndReload(objToSave);
950			} catch (NotActiveException ce) {
951				causedException = true;
952			}
953			assertTrue("WriteFieldsWithoutFetchingPutFields", causedException);
954
955		} catch (IOException e) {
956			fail("IOException serializing " + objToSave + " : "
957					+ e.getMessage());
958		} catch (ClassNotFoundException e) {
959			fail("ClassNotFoundException reading Object type : "
960					+ e.getMessage());
961		} catch (Error err) {
962			System.out.println("Error when obj = " + objToSave);
963			// err.printStackTrace();
964			throw err;
965		}
966	}
967
968	public void test_18_46_writeObject() {
969		// Test for method void
970		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
971
972		Object objToSave = null;
973		Object objLoaded;
974
975		try {
976			objToSave = SerialPersistentFields.class; // Test for 1FA7TA6
977			if (DEBUG)
978				System.out.println("Obj = " + objToSave);
979			objLoaded = dumpAndReload(objToSave);
980			// Has to be able to save/load an exception
981			assertTrue(MSG_TEST_FAILED + objToSave, true);
982
983		} catch (IOException e) {
984			fail("IOException serializing " + objToSave + " : "
985					+ e.getMessage());
986		} catch (ClassNotFoundException e) {
987			fail("ClassNotFoundException reading Object type : "
988					+ e.getMessage());
989		} catch (Error err) {
990			System.out.println("Error when obj = " + objToSave);
991			// err.printStackTrace();
992			throw err;
993		}
994	}
995
996	public void test_18_47_writeObject() {
997		// Test for method void
998		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
999
1000		Object objToSave = null;
1001		Object objLoaded;
1002
1003		try {
1004			objToSave = ObjectStreamClass.lookup(SerialPersistentFields.class); // Test
1005			// for
1006			// 1FA7TA6
1007			if (DEBUG)
1008				System.out.println("Obj = " + objToSave);
1009			objLoaded = dumpAndReload(objToSave);
1010			// Has to be able to save/load an exception
1011			assertTrue(MSG_TEST_FAILED + objToSave, true);
1012
1013		} catch (IOException e) {
1014			fail("IOException serializing " + objToSave + " : "
1015					+ e.getMessage());
1016		} catch (ClassNotFoundException e) {
1017			fail("ClassNotFoundException reading Object type : "
1018					+ e.getMessage());
1019		} catch (Error err) {
1020			System.out.println("Error when obj = " + objToSave);
1021			// err.printStackTrace();
1022			throw err;
1023		}
1024	}
1025
1026	public void test_18_48_writeObject() {
1027		// Test for method void
1028		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1029
1030		Object objToSave = null;
1031		Object objLoaded;
1032
1033		try {
1034			SerialPersistentFieldsWithoutField spf = new SerialPersistentFieldsWithoutField();
1035			final int CONST = -500;
1036			spf.anInstanceVar = CONST;
1037			objToSave = spf;
1038			if (DEBUG)
1039				System.out.println("Obj = " + objToSave);
1040			objLoaded = dumpAndReload(objToSave);
1041			assertTrue(
1042					"serialPersistentFields do not work properly in this implementation",
1043					((SerialPersistentFieldsWithoutField) objLoaded).anInstanceVar != CONST);
1044
1045		} catch (IOException e) {
1046			fail("IOException serializing " + objToSave + " : "
1047					+ e.getMessage());
1048		} catch (ClassNotFoundException e) {
1049			fail("ClassNotFoundException reading Object type : "
1050					+ e.getMessage());
1051		} catch (Error err) {
1052			System.out.println("Error when obj = " + objToSave);
1053			// err.printStackTrace();
1054			throw err;
1055		}
1056	}
1057
1058	public void test_18_49_writeObject() {
1059		// Test for method void
1060		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1061
1062		Object objToSave = null;
1063		Object objLoaded;
1064
1065		try {
1066			java.net.SocketPermission p = new java.net.SocketPermission(
1067					"www.yahoo.com", "connect");
1068			objToSave = p;
1069			if (DEBUG)
1070				System.out.println("Obj = " + objToSave);
1071			objLoaded = dumpAndReload(objToSave);
1072			assertTrue("SocketPermissions are not the same: " + p + "\t,\t"
1073					+ objLoaded, p.equals(objLoaded));
1074
1075		} catch (IOException e) {
1076			fail("IOException serializing " + objToSave + " : "
1077					+ e.getMessage());
1078		} catch (ClassNotFoundException e) {
1079			fail("ClassNotFoundException reading Object type : "
1080					+ e.getMessage());
1081		} catch (Error err) {
1082			System.out.println("Error when obj = " + objToSave);
1083			// err.printStackTrace();
1084			throw err;
1085		}
1086	}
1087
1088	public void test_18_50_writeObject() {
1089		// Test for method void
1090		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1091
1092		Object objToSave = null;
1093		Object objLoaded;
1094
1095		try {
1096			java.net.SocketPermission p = new java.net.SocketPermission(
1097					"www.yahoo.com", "ReSoLVe,  		ConNecT");
1098			objToSave = p;
1099			if (DEBUG)
1100				System.out.println("Obj = " + objToSave);
1101			objLoaded = dumpAndReload(objToSave);
1102			assertTrue("SocketPermissions are not the same: " + p + "\t,\t"
1103					+ objLoaded, p.equals(objLoaded));
1104
1105		} catch (IOException e) {
1106			fail("IOException serializing " + objToSave + " : "
1107					+ e.getMessage());
1108		} catch (ClassNotFoundException e) {
1109			fail("ClassNotFoundException reading Object type : "
1110					+ e.getMessage());
1111		} catch (Error err) {
1112			System.out.println("Error when obj = " + objToSave);
1113			// err.printStackTrace();
1114			throw err;
1115		}
1116	}
1117
1118	public void test_18_51_writeObject() {
1119		// Test for method void
1120		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1121
1122		Object objToSave = null;
1123		Object objLoaded;
1124
1125		try {
1126
1127			ReadWriteObjectAndPrimitiveData readWrite = new ReadWriteObjectAndPrimitiveData();
1128			objToSave = readWrite;
1129			if (DEBUG)
1130				System.out.println("Obj = " + objToSave);
1131			objLoaded = dumpAndReload(objToSave);
1132			// has to have called the writeObject on the instance to dump
1133			assertTrue(MSG_TEST_FAILED + objToSave, readWrite.calledWriteObject);
1134			// has to have called the readObject on the instance loaded
1135			assertTrue(
1136					MSG_TEST_FAILED + objToSave,
1137					((ReadWriteObjectAndPrimitiveData) objLoaded).calledReadObject);
1138
1139		} catch (IOException e) {
1140			fail("IOException serializing " + objToSave + " : "
1141					+ e.getMessage());
1142		} catch (ClassNotFoundException e) {
1143			fail("ClassNotFoundException reading Object type : "
1144					+ e.getMessage());
1145		} catch (Error err) {
1146			System.out.println("Error when obj = " + objToSave);
1147			// err.printStackTrace();
1148			throw err;
1149		}
1150	}
1151
1152	public void test_18_52_writeObject() {
1153		// Test for method void
1154		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1155
1156		Object objToSave = null;
1157		Object objLoaded;
1158
1159		try {
1160
1161			ArrayList list = new ArrayList<String>(Arrays.asList(new String[] { "a",
1162					"list", "of", "strings" }));
1163			objToSave = list;
1164			if (DEBUG)
1165				System.out.println("Obj = " + objToSave);
1166			objLoaded = dumpAndReload(objToSave);
1167			// Has to have worked
1168			assertTrue(MSG_TEST_FAILED + objToSave, true);
1169
1170		} catch (IOException e) {
1171			fail("IOException serializing " + objToSave + " : "
1172					+ e.getMessage());
1173		} catch (ClassNotFoundException e) {
1174			fail("ClassNotFoundException reading Object type : "
1175					+ e.getMessage());
1176		} catch (Error err) {
1177			System.out.println("Error when obj = " + objToSave);
1178			// err.printStackTrace();
1179			throw err;
1180		}
1181	}
1182
1183	public void test_18_53_writeObject() {
1184		// Test for method void
1185		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1186
1187		Object objToSave = null;
1188		Object objLoaded;
1189
1190		try {
1191
1192			objToSave = Locale.CHINESE;
1193			if (DEBUG)
1194				System.out.println("Obj = " + objToSave);
1195			objLoaded = dumpAndReload(objToSave);
1196			// Has to have worked
1197			assertTrue(MSG_TEST_FAILED + objToSave, true);
1198
1199		} catch (IOException e) {
1200			fail("IOException serializing " + objToSave + " : "
1201					+ e.getMessage());
1202		} catch (ClassNotFoundException e) {
1203			fail("ClassNotFoundException reading Object type : "
1204					+ e.getMessage());
1205		} catch (Error err) {
1206			System.out.println("Error when obj = " + objToSave);
1207			// err.printStackTrace();
1208			throw err;
1209		}
1210	}
1211
1212	public void test_OptionalDataNotRead() {
1213		// Test for method void
1214		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1215
1216		Object objToSave = null;
1217		Object objLoaded;
1218
1219		try {
1220			OptionalDataNotRead test = new OptionalDataNotRead();
1221			// Have to save an object after the one above, and when we read it,
1222			// it cannot be a byte[]
1223			Date now = new Date();
1224			Object[] twoObjects = new Object[2];
1225			twoObjects[0] = test;
1226			twoObjects[1] = now;
1227			objToSave = twoObjects;
1228			if (DEBUG)
1229				System.out.println("Obj = " + objToSave);
1230			objLoaded = dumpAndReload(objToSave);
1231			// Has to have worked
1232			Object[] twoLoadedObjects = (Object[]) objLoaded;
1233			assertTrue(MSG_TEST_FAILED + objToSave, twoLoadedObjects[0]
1234					.getClass() == OptionalDataNotRead.class);
1235			assertTrue(MSG_TEST_FAILED + objToSave, twoLoadedObjects[1]
1236					.getClass() == Date.class);
1237
1238		} catch (IOException e) {
1239			fail("IOException serializing " + objToSave + " : "
1240					+ e.getMessage());
1241		} catch (ClassNotFoundException e) {
1242			fail("ClassNotFoundException reading Object type : "
1243					+ e.getMessage());
1244		} catch (Error err) {
1245			System.out.println("Error when obj = " + objToSave);
1246			// err.printStackTrace();
1247			throw err;
1248		}
1249	}
1250
1251	public void test_18_55_writeObject() {
1252		// Test for method void
1253		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1254
1255		Object objToSave = null;
1256		Object objLoaded;
1257
1258		try {
1259			Object[] threeObjects = new Object[3];
1260			threeObjects[0] = new Integer(2);
1261			threeObjects[1] = Date.class;
1262			threeObjects[2] = threeObjects[0]; // has to be the same
1263			objToSave = threeObjects;
1264			if (DEBUG)
1265				System.out.println("Obj = " + objToSave);
1266			objLoaded = dumpAndReload(objToSave);
1267			// Has to have worked
1268			Object[] threeLoadedObjects = (Object[]) objLoaded;
1269			assertTrue(MSG_TEST_FAILED + objToSave, threeLoadedObjects[0]
1270					.getClass() == Integer.class);
1271			assertTrue(MSG_TEST_FAILED + objToSave,
1272					threeLoadedObjects[1] == Date.class);
1273			assertTrue(MSG_TEST_FAILED + objToSave,
1274					threeLoadedObjects[0] == threeLoadedObjects[2]);
1275
1276		} catch (IOException e) {
1277			fail("IOException serializing " + objToSave + " : "
1278					+ e.getMessage());
1279		} catch (ClassNotFoundException e) {
1280			fail("ClassNotFoundException reading Object type : "
1281					+ e.getMessage());
1282		} catch (Error err) {
1283			System.out.println("Error when obj = " + objToSave);
1284			// err.printStackTrace();
1285			throw err;
1286		}
1287	}
1288
1289	public void test_18_56_writeObject() {
1290		// Test for method void
1291		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1292
1293		Object objToSave = null;
1294		Object objLoaded;
1295
1296		try {
1297			// Test for 1FD24BY
1298			NestedPutField test = new NestedPutField();
1299			objToSave = test;
1300			if (DEBUG)
1301				System.out.println("Obj = " + objToSave);
1302			objLoaded = dumpAndReload(objToSave);
1303			// Has to have worked
1304			assertNotNull(MSG_TEST_FAILED + objToSave,
1305					((NestedPutField) objLoaded).field1);
1306
1307		} catch (IOException e) {
1308			fail("IOException serializing " + objToSave + " : "
1309					+ e.getMessage());
1310		} catch (ClassNotFoundException e) {
1311			fail("ClassNotFoundException reading Object type : "
1312					+ e.getMessage());
1313		} catch (Error err) {
1314			System.out.println("Error when obj = " + objToSave);
1315			// err.printStackTrace();
1316			throw err;
1317		}
1318	}
1319
1320	public void test_18_57_writeObject() {
1321		// Test for method void
1322		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1323
1324		Object objToSave = null;
1325		Object objLoaded;
1326
1327		try {
1328			ByteArrayOutputStream out;
1329			StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping;
1330
1331			out = new ByteArrayOutputStream();
1332			streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping(
1333					out);
1334			;
1335			objToSave = FOO.getClass();
1336			if (DEBUG)
1337				System.out.println("Obj = " + objToSave);
1338			streamBasedReplacementWhenDumping.writeObject(objToSave);
1339			// Has to have run the replacement method
1340			assertTrue("Executed replacement when it should not: " + objToSave,
1341					!streamBasedReplacementWhenDumping.calledClassReplacement);
1342
1343		} catch (IOException e) {
1344			fail("Exception serializing " + objToSave + "\t->"
1345					+ e.toString());
1346		} catch (Error err) {
1347			System.out.println("Error " + err + " when obj = " + objToSave);
1348			throw err;
1349		}
1350	}
1351
1352	public void test_18_58_writeObject() {
1353		// Test for method void
1354		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1355
1356		Object objToSave = null;
1357		Object objLoaded;
1358
1359		try {
1360			ByteArrayOutputStream out;
1361			StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping;
1362
1363			out = new ByteArrayOutputStream();
1364			streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping(
1365					out);
1366			;
1367			objToSave = ObjectStreamClass.lookup(FOO.getClass());
1368			if (DEBUG)
1369				System.out.println("Obj = " + objToSave);
1370			streamBasedReplacementWhenDumping.writeObject(objToSave);
1371			// Has to have run the replacement method
1372			assertTrue(
1373					"Executed replacement when it should not: " + objToSave,
1374					!streamBasedReplacementWhenDumping.calledObjectStreamClassReplacement);
1375
1376		} catch (IOException e) {
1377			fail("Exception serializing " + objToSave + "\t->"
1378					+ e.toString());
1379		} catch (Error err) {
1380			System.out.println("Error " + err + " when obj = " + objToSave);
1381			throw err;
1382		}
1383	}
1384
1385	public void test_18_59_writeObject() {
1386		// Test for method void
1387		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1388
1389		Object objToSave = null;
1390		Object objLoaded;
1391
1392		try {
1393			ByteArrayOutputStream out;
1394			StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping;
1395
1396			out = new ByteArrayOutputStream();
1397			streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping(
1398					out);
1399			;
1400			objToSave = new int[3];
1401			if (DEBUG)
1402				System.out.println("Obj = " + objToSave);
1403			streamBasedReplacementWhenDumping.writeObject(objToSave);
1404			// Has to have run the replacement method
1405			assertTrue("DId not execute replacement when it should: "
1406					+ objToSave,
1407					streamBasedReplacementWhenDumping.calledArrayReplacement);
1408
1409		} catch (IOException e) {
1410			fail("Exception serializing " + objToSave + "\t->"
1411					+ e.toString());
1412		} catch (Error err) {
1413			System.out.println("Error " + err + " when obj = " + objToSave);
1414			throw err;
1415		}
1416	}
1417
1418	public void test_18_60_writeObject() {
1419		// Test for method void
1420		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1421
1422		Object objToSave = null;
1423		Object objLoaded;
1424
1425		try {
1426			ByteArrayOutputStream out;
1427			StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping;
1428
1429			out = new ByteArrayOutputStream();
1430			streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping(
1431					out);
1432			;
1433			objToSave = FOO;
1434			if (DEBUG)
1435				System.out.println("Obj = " + objToSave);
1436			streamBasedReplacementWhenDumping.writeObject(objToSave);
1437			// Has to have run the replacement method
1438			assertTrue("Did not execute replacement when it should: "
1439					+ objToSave,
1440					streamBasedReplacementWhenDumping.calledStringReplacement);
1441
1442		} catch (IOException e) {
1443			fail("Exception serializing " + objToSave + "\t->"
1444					+ e.toString());
1445		} catch (Error err) {
1446			System.out.println("Error " + err + " when obj = " + objToSave);
1447			throw err;
1448		}
1449	}
1450
1451	public void test_18_61_writeObject() {
1452		// Test for method void
1453		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1454
1455		Object objToSave = null;
1456		Object objLoaded;
1457
1458		try {
1459			ArrayOfSerializable test = new ArrayOfSerializable();
1460			objToSave = test;
1461			if (DEBUG)
1462				System.out.println("Obj = " + objToSave);
1463			objLoaded = dumpAndReload(objToSave);
1464			// Has to have worked
1465			assertTrue(MSG_TEST_FAILED + objToSave, true);
1466
1467		} catch (IOException e) {
1468			fail("IOException serializing " + objToSave + " : "
1469					+ e.getMessage());
1470		} catch (ClassNotFoundException e) {
1471			fail("ClassNotFoundException reading Object type : "
1472					+ e.getMessage());
1473		} catch (Error err) {
1474			System.out.println("Error when obj = " + objToSave);
1475			// err.printStackTrace();
1476			throw err;
1477		}
1478	}
1479
1480	public void test_18_62_writeObject() {
1481		// Test for method void
1482		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1483
1484		Object objToSave = null;
1485		Object objLoaded;
1486
1487		try {
1488			ClassSubClassTest1 test = new ClassSubClassTest1(
1489					"SuperInitialString", "SubInitialString");
1490			objToSave = test;
1491			if (DEBUG)
1492				System.out.println("Obj = " + objToSave);
1493			objLoaded = dumpAndReload(objToSave);
1494			// Has to have worked
1495			assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded));
1496
1497		} catch (IOException e) {
1498			fail("IOException serializing " + objToSave + " : "
1499					+ e.getMessage());
1500		} catch (ClassNotFoundException e) {
1501			fail("ClassNotFoundException reading Object type : "
1502					+ e.getMessage());
1503		} catch (Error err) {
1504			System.out.println("Error when obj = " + objToSave);
1505			// err.printStackTrace();
1506			throw err;
1507		}
1508	}
1509
1510	public void test_18_63_writeObject() {
1511		// Test for method void
1512		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1513
1514		Object objToSave = null;
1515		Object objLoaded;
1516
1517		try {
1518			ConstructorTestC test = new ConstructorTestC();
1519			objToSave = test;
1520			if (DEBUG)
1521				System.out.println("Obj = " + objToSave);
1522			objLoaded = dumpAndReload(objToSave);
1523			// Has to have worked
1524			assertTrue(MSG_TEST_FAILED + objToSave, test.verify(objLoaded));
1525
1526		} catch (IOException e) {
1527			fail("IOException serializing " + objToSave + " : "
1528					+ e.getMessage());
1529		} catch (ClassNotFoundException e) {
1530			fail("ClassNotFoundException reading Object type : "
1531					+ e.getMessage());
1532		} catch (Error err) {
1533			System.out.println("Error when obj = " + objToSave);
1534			// err.printStackTrace();
1535			throw err;
1536		}
1537	}
1538
1539	public void test_18_64_writeObject() {
1540		// Test for method void
1541		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1542
1543		Object objToSave = null;
1544		Object objLoaded;
1545
1546		try {
1547			HashCodeTest test = new HashCodeTest();
1548			objToSave = test;
1549			if (DEBUG)
1550				System.out.println("Obj = " + objToSave);
1551			objLoaded = dumpAndReload(objToSave);
1552			// Has to have worked
1553			assertTrue(MSG_TEST_FAILED + objToSave,
1554					!((HashCodeTest) objLoaded).serializationUsesHashCode);
1555
1556		} catch (IOException e) {
1557			fail("IOException serializing " + objToSave + " : "
1558					+ e.getMessage());
1559		} catch (ClassNotFoundException e) {
1560			fail("ClassNotFoundException reading Object type : "
1561					+ e.getMessage());
1562		} catch (Error err) {
1563			System.out.println("Error when obj = " + objToSave);
1564			// err.printStackTrace();
1565			throw err;
1566		}
1567	}
1568
1569	public void test_18_65_writeObject() {
1570		// Test for method void
1571		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1572
1573		Object objToSave = null;
1574		Object objLoaded;
1575
1576		try {
1577			InitializerFieldsTest test = new InitializerFieldsTest();
1578			test.toBeSerialized = "serializing";
1579			InitializerFieldsTest.toBeNotSerialized = "It should not have this value after loaded from a File";
1580			InitializerFieldsTest.toBeNotSerialized2 = "Good-This is the rigth value.";
1581
1582			objToSave = test;
1583			if (DEBUG)
1584				System.out.println("Obj = " + objToSave);
1585			dump(objToSave);
1586			InitializerFieldsTest.toBeNotSerialized = new String(
1587					InitializerFieldsTest.toBeNotSerialized2);
1588			objLoaded = reload();
1589
1590			// Has to have worked
1591			assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded)));
1592
1593		} catch (IOException e) {
1594			fail("IOException serializing " + objToSave + " : "
1595					+ e.getMessage());
1596		} catch (ClassNotFoundException e) {
1597			fail("ClassNotFoundException reading Object type : "
1598					+ e.getMessage());
1599		} catch (Error err) {
1600			System.out.println("Error when obj = " + objToSave);
1601			// err.printStackTrace();
1602			throw err;
1603		}
1604	}
1605
1606	public void test_18_66_writeObject() {
1607		// Test for method void
1608		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1609
1610		Object objToSave = null;
1611		Object objLoaded;
1612
1613		try {
1614			InitializerFieldsTest2 test = new InitializerFieldsTest2();
1615			test.toBeSerialized = "serializing";
1616			test.toBeSerialized3 = "serializing3";
1617			test.toBeSerialized4 = "serializing4";
1618			test.toBeSerialized5 = "serializing5";
1619			InitializerFieldsTest2.toBeNotSerialized = "It should not have this value after loaded from a File";
1620			InitializerFieldsTest2.toBeNotSerialized2 = "Good-This is the rigth value.";
1621
1622			objToSave = test;
1623			if (DEBUG)
1624				System.out.println("Obj = " + objToSave);
1625			dump(objToSave);
1626			InitializerFieldsTest2.toBeNotSerialized = new String(
1627					InitializerFieldsTest2.toBeNotSerialized2);
1628			objLoaded = reload();
1629
1630			// Has to have worked
1631			assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded)));
1632
1633		} catch (IOException e) {
1634			fail("IOException serializing " + objToSave + " : "
1635					+ e.getMessage());
1636		} catch (ClassNotFoundException e) {
1637			fail("ClassNotFoundException reading Object type : "
1638					+ e.getMessage());
1639		} catch (Error err) {
1640			System.out.println("Error when obj = " + objToSave);
1641			// err.printStackTrace();
1642			throw err;
1643		}
1644	}
1645
1646	public void test_18_67_writeObject() {
1647		// Test for method void
1648		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1649
1650		Object objToSave = null;
1651		Object objLoaded;
1652
1653		try {
1654			InitializerFieldsTest3 test = new InitializerFieldsTest3();
1655			test.toBeSerialized = "serializing";
1656			test.toBeSerialized3 = "serializing3";
1657			test.toBeSerialized4 = "serializing4";
1658			test.toBeSerialized5 = "serializing5";
1659			InitializerFieldsTest2.toBeNotSerialized = "It should not have this value after loaded from a File";
1660			InitializerFieldsTest2.toBeNotSerialized2 = "Good-This is the rigth value.";
1661			test.sub_toBeSerialized = "serializingSub";
1662			test.sub_toBeSerialized3 = "serializing3sub";
1663			test.sub_toBeSerialized4 = "serializing4sub";
1664			test.sub_toBeSerialized5 = "serializing5sub";
1665			InitializerFieldsTest3.sub_toBeNotSerialized = "(Subclass) It should not have this value after loaded from a File";
1666			InitializerFieldsTest3.sub_toBeNotSerialized2 = "(Subclass) Good-This is the rigth value.";
1667			// Before dumping the two static vars are differents.
1668			// After dumping the value of toBeNotSerialized2 is put in
1669			// toBeNotSerialized
1670			// After loading it must be the same.
1671			objToSave = test;
1672			if (DEBUG)
1673				System.out.println("Obj = " + objToSave);
1674			dump(objToSave);
1675			InitializerFieldsTest2.toBeNotSerialized = new String(
1676					InitializerFieldsTest2.toBeNotSerialized2);
1677			InitializerFieldsTest3.sub_toBeNotSerialized = new String(
1678					InitializerFieldsTest3.sub_toBeNotSerialized2);
1679			objLoaded = reload();
1680
1681			// Has to have worked
1682			assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded)));
1683
1684		} catch (IOException e) {
1685			fail("IOException serializing " + objToSave + " : "
1686					+ e.getMessage());
1687		} catch (ClassNotFoundException e) {
1688			fail("ClassNotFoundException reading Object type : "
1689					+ e.getMessage());
1690		} catch (Error err) {
1691			System.out.println("Error when obj = " + objToSave);
1692			// err.printStackTrace();
1693			throw err;
1694		}
1695	}
1696
1697	public void test_DeepNesting() {
1698		// Test for method void
1699		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1700
1701		Object objToSave = null;
1702		Object objLoaded;
1703
1704		try {
1705			DeepNesting test = new DeepNesting(50);
1706			objToSave = test;
1707			if (DEBUG)
1708				System.out.println("Obj = " + objToSave);
1709			objLoaded = dumpAndReload(objToSave);
1710
1711			// Has to have worked
1712			assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded)));
1713
1714		} catch (IOException e) {
1715			fail("IOException serializing " + objToSave + " : "
1716					+ e.getMessage());
1717		} catch (ClassNotFoundException e) {
1718			fail("ClassNotFoundException reading Object type : "
1719					+ e.getMessage());
1720		} catch (Error err) {
1721			// err.printStackTrace();
1722			System.out.println("Error " + err + " when obj = " + objToSave);
1723			throw err;
1724		}
1725	}
1726
1727	public void test_DeepNestingWithWriteObject() {
1728		// Test for method void
1729		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1730
1731		Object objToSave = null;
1732		Object objLoaded;
1733
1734		try {
1735			DeepNestingWithWriteObject test = new DeepNestingWithWriteObject(50);
1736			objToSave = test;
1737			if (DEBUG)
1738				System.out.println("Obj = " + objToSave);
1739			objLoaded = dumpAndReload(objToSave);
1740
1741			// Has to have worked
1742			assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded)));
1743
1744		} catch (IOException e) {
1745			fail("IOException serializing " + objToSave + " : "
1746					+ e.getMessage());
1747		} catch (ClassNotFoundException e) {
1748			fail("ClassNotFoundException reading Object type : "
1749					+ e.getMessage());
1750		} catch (Error err) {
1751			// err.printStackTrace();
1752			System.out.println("Error " + err + " when obj = " + objToSave);
1753			throw err;
1754		}
1755	}
1756
1757	public void test_18_69_writeObject() {
1758		// Test for method void
1759		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1760
1761		Object objToSave = null;
1762		Object objLoaded;
1763
1764		try {
1765			NonPublicClassTest test = new NonPublicClassTest();
1766			test.x10();
1767			objToSave = test;
1768			if (DEBUG)
1769				System.out.println("Obj = " + objToSave);
1770			objLoaded = dumpAndReload(objToSave);
1771
1772			// Has to have worked
1773			assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded)));
1774
1775		} catch (IOException e) {
1776			fail("IOException serializing " + objToSave + " : "
1777					+ e.getMessage());
1778		} catch (ClassNotFoundException e) {
1779			fail("ClassNotFoundException reading Object type : "
1780					+ e.getMessage());
1781		} catch (Error err) {
1782			System.out.println("Error when obj = " + objToSave);
1783			// err.printStackTrace();
1784			throw err;
1785		}
1786	}
1787
1788	public void test_18_70_writeObject() {
1789		// Test for method void
1790		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1791
1792		Object objToSave = null;
1793		Object objLoaded;
1794
1795		try {
1796			int[] test = new int[1];
1797			int intValue = 0;
1798			test[0] = intValue;
1799			objToSave = test;
1800			if (DEBUG)
1801				System.out.println("Obj = " + objToSave);
1802			objLoaded = dumpAndReload(objToSave);
1803
1804			// Has to have worked
1805			assertTrue(MSG_TEST_FAILED + objToSave, Arrays.equals(test,
1806					(int[]) objLoaded));
1807
1808		} catch (IOException e) {
1809			fail("IOException serializing " + objToSave + " : "
1810					+ e.getMessage());
1811		} catch (ClassNotFoundException e) {
1812			fail("ClassNotFoundException reading Object type : "
1813					+ e.getMessage());
1814		} catch (Error err) {
1815			System.out.println("Error when obj = " + objToSave);
1816			// err.printStackTrace();
1817			throw err;
1818		}
1819	}
1820
1821	public void test_18_71_writeObject() {
1822		// Test for method void
1823		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1824
1825		Object objToSave = null;
1826		Object objLoaded;
1827
1828		try {
1829			int i, j, maxJ = 3, maxI = 200;
1830			byte[][] obj = new byte[maxJ][maxI];
1831			for (j = 0; j < maxJ; j++) {
1832				for (i = 0; i < maxI; i++)
1833					obj[j][i] = (byte) (i - 100);
1834			}
1835			objToSave = obj;
1836			if (DEBUG)
1837				System.out.println("Obj = " + objToSave);
1838			objLoaded = dumpAndReload(objToSave);
1839			byte[][] toCompare = (byte[][]) objLoaded;
1840
1841			boolean ok = true;
1842			// Has to have worked
1843			for (j = 0; j < maxJ; j++) {
1844				for (i = 0; i < maxI; i++)
1845					if (obj[j][i] != toCompare[j][i]) {
1846						ok = false;
1847						break;
1848					}
1849			}
1850
1851			assertTrue(MSG_TEST_FAILED + objToSave, ok);
1852
1853		} catch (IOException e) {
1854			fail("IOException serializing " + objToSave + " : "
1855					+ e.getMessage());
1856		} catch (ClassNotFoundException e) {
1857			fail("ClassNotFoundException reading Object type : "
1858					+ e.getMessage());
1859		} catch (Error err) {
1860			System.out.println("Error when obj = " + objToSave);
1861			// err.printStackTrace();
1862			throw err;
1863		}
1864	}
1865
1866	public void test_18_72_writeObject() {
1867		// Test for method void
1868		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1869
1870		Object objToSave = null;
1871		Object objLoaded;
1872
1873		try {
1874			int i, j, maxJ = 3, maxI = 200;
1875			int[][] obj = new int[maxJ][maxI];
1876			for (j = 0; j < maxJ; j++) {
1877				for (i = 0; i < maxI; i++)
1878					obj[j][i] = (i - 100);
1879			}
1880			objToSave = obj;
1881			if (DEBUG)
1882				System.out.println("Obj = " + objToSave);
1883			objLoaded = dumpAndReload(objToSave);
1884			int[][] toCompare = (int[][]) objLoaded;
1885
1886			boolean ok = true;
1887			// Has to have worked
1888			for (j = 0; j < maxJ; j++) {
1889				for (i = 0; i < maxI; i++)
1890					if (obj[j][i] != toCompare[j][i]) {
1891						ok = false;
1892						break;
1893					}
1894			}
1895
1896			assertTrue(MSG_TEST_FAILED + objToSave, ok);
1897
1898		} catch (IOException e) {
1899			fail("IOException serializing " + objToSave + " : "
1900					+ e.getMessage());
1901		} catch (ClassNotFoundException e) {
1902			fail("ClassNotFoundException reading Object type : "
1903					+ e.getMessage());
1904		} catch (Error err) {
1905			System.out.println("Error when obj = " + objToSave);
1906			// err.printStackTrace();
1907			throw err;
1908		}
1909	}
1910
1911	public void test_18_73_writeObject() {
1912		// Test for method void
1913		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1914
1915		Object objToSave = null;
1916		Object objLoaded;
1917
1918		try {
1919			String org = "abcdefghijklmnopqrstuvxyz1234567890abcdefghijklmnopqrstuvxyz1234567890";
1920			int i, j, maxJ = 3, maxI = 70;
1921			String[][] obj = new String[maxJ][maxI];
1922			for (j = 0; j < maxJ; j++) {
1923				for (i = 0; i < maxI; i++)
1924					obj[j][i] = org.substring(0, i);
1925			}
1926			objToSave = obj;
1927			if (DEBUG)
1928				System.out.println("Obj = " + objToSave);
1929			objLoaded = dumpAndReload(objToSave);
1930			String[][] toCompare = (String[][]) objLoaded;
1931
1932			boolean ok = true;
1933			// Has to have worked
1934			for (j = 0; j < maxJ; j++) {
1935				for (i = 0; i < maxI; i++)
1936					if (!obj[j][i].equals(toCompare[j][i])) {
1937						ok = false;
1938						break;
1939					}
1940			}
1941
1942			assertTrue(MSG_TEST_FAILED + objToSave, ok);
1943
1944		} catch (IOException e) {
1945			fail("IOException serializing " + objToSave + " : "
1946					+ e.getMessage());
1947		} catch (ClassNotFoundException e) {
1948			fail("ClassNotFoundException reading Object type : "
1949					+ e.getMessage());
1950		} catch (Error err) {
1951			System.out.println("Error when obj = " + objToSave);
1952			// err.printStackTrace();
1953			throw err;
1954		}
1955	}
1956
1957	public void test_18_74_writeObject() {
1958		// Test for method void
1959		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1960
1961		Object objToSave = null;
1962		Object objLoaded;
1963
1964		try {
1965			SameInstVarNameSubClass test = new SameInstVarNameSubClass(100);
1966			objToSave = test;
1967			if (DEBUG)
1968				System.out.println("Obj = " + objToSave);
1969			objLoaded = dumpAndReload(objToSave);
1970			// Has to have worked
1971			assertTrue(MSG_TEST_FAILED + objToSave,
1972					((SameInstVarNameSubClass) objLoaded).foo == 100);
1973
1974		} catch (IOException e) {
1975			fail("IOException serializing " + objToSave + " : "
1976					+ e.getMessage());
1977		} catch (ClassNotFoundException e) {
1978			fail("ClassNotFoundException reading Object type : "
1979					+ e.getMessage());
1980		} catch (Error err) {
1981			System.out.println("Error when obj = " + objToSave);
1982			// err.printStackTrace();
1983			throw err;
1984		}
1985	}
1986
1987	public void test_18_75_writeObject() {
1988		// Test for method void
1989		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
1990
1991		Object objToSave = null;
1992		Object objLoaded;
1993
1994		try {
1995			SInterfaceTest test = new SInterfaceTest();
1996			objToSave = test;
1997			if (DEBUG)
1998				System.out.println("Obj = " + objToSave);
1999			objLoaded = dumpAndReload(objToSave);
2000			// Has to have worked
2001			assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded));
2002
2003		} catch (IOException e) {
2004			fail("IOException serializing " + objToSave + " : "
2005					+ e.getMessage());
2006		} catch (ClassNotFoundException e) {
2007			fail("ClassNotFoundException reading Object type : "
2008					+ e.getMessage());
2009		} catch (Error err) {
2010			System.out.println("Error when obj = " + objToSave);
2011			// err.printStackTrace();
2012			throw err;
2013		}
2014	}
2015
2016	public void test_18_76_writeObject() {
2017		// Test for method void
2018		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
2019
2020		Object objToSave = null;
2021		Object objLoaded;
2022
2023		try {
2024			SInterfaceTest2 test = new SInterfaceTest2();
2025			objToSave = test;
2026			if (DEBUG)
2027				System.out.println("Obj = " + objToSave);
2028			objLoaded = dumpAndReload(objToSave);
2029			// Has to have worked
2030			assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded));
2031
2032		} catch (IOException e) {
2033			fail("IOException serializing " + objToSave + " : "
2034					+ e.getMessage());
2035		} catch (ClassNotFoundException e) {
2036			fail("ClassNotFoundException reading Object type : "
2037					+ e.getMessage());
2038		} catch (Error err) {
2039			System.out.println("Error when obj = " + objToSave);
2040			// err.printStackTrace();
2041			throw err;
2042		}
2043	}
2044
2045	public void test_18_77_writeObject() {
2046		// Test for method void
2047		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
2048
2049		Object objToSave = null;
2050		Object objLoaded;
2051
2052		try {
2053			SuperclassTest test = new SuperclassTest();
2054			objToSave = test;
2055			if (DEBUG)
2056				System.out.println("Obj = " + objToSave);
2057			objLoaded = dumpAndReload(objToSave);
2058			// Has to have worked
2059			assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded));
2060
2061		} catch (IOException e) {
2062			fail("IOException serializing " + objToSave + " : "
2063					+ e.getMessage());
2064		} catch (ClassNotFoundException e) {
2065			fail("ClassNotFoundException reading Object type : "
2066					+ e.getMessage());
2067		} catch (Error err) {
2068			System.out.println("Error when obj = " + objToSave);
2069			// err.printStackTrace();
2070			throw err;
2071		}
2072	}
2073
2074	public void test_18_78_writeObject() {
2075		// Test for method void
2076		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
2077
2078		Object objToSave = null;
2079		Object objLoaded;
2080
2081		try {
2082			SuperclassTest2 test = new SuperclassTest2();
2083			objToSave = test;
2084			if (DEBUG)
2085				System.out.println("Obj = " + objToSave);
2086			objLoaded = dumpAndReload(objToSave);
2087			// Has to have worked
2088			assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded));
2089
2090		} catch (IOException e) {
2091			fail("IOException serializing " + objToSave + " : "
2092					+ e.getMessage());
2093		} catch (ClassNotFoundException e) {
2094			fail("ClassNotFoundException reading Object type : "
2095					+ e.getMessage());
2096		} catch (Error err) {
2097			System.out.println("Error when obj = " + objToSave);
2098			// err.printStackTrace();
2099			throw err;
2100		}
2101	}
2102
2103	public void test_18_79_writeObject() {
2104		// Test for method void
2105		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
2106
2107		Object objToSave = null;
2108		Object objLoaded;
2109
2110		try {
2111			SyntheticFieldTest test = new SyntheticFieldTest();
2112			objToSave = test;
2113			if (DEBUG)
2114				System.out.println("Obj = " + objToSave);
2115			objLoaded = dumpAndReload(objToSave);
2116			// Has to have worked
2117			assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded));
2118
2119		} catch (IOException e) {
2120			fail("IOException serializing " + objToSave + " : "
2121					+ e.getMessage());
2122		} catch (ClassNotFoundException e) {
2123			fail("ClassNotFoundException reading Object type : "
2124					+ e.getMessage());
2125		} catch (Error err) {
2126			System.out.println("Error when obj = " + objToSave);
2127			// err.printStackTrace();
2128			throw err;
2129		}
2130	}
2131
2132	public void test_18_80_writeObject() {
2133		// Test for method void
2134		// java.io.ObjectOutputStream.writeObject(java.lang.Object)
2135
2136		try {
2137			ByteArrayOutputStream out = new ByteArrayOutputStream();
2138			DataOutputStream dos = new DataOutputStream(out);
2139			new ObjectOutputStream(dos); // just to make sure we get a header
2140			dos.writeByte(ObjectStreamConstants.TC_BLOCKDATA);
2141			int length = 99;
2142			dos.writeByte(length);
2143			for (int i = 0; i < length; i++) {
2144				dos.writeByte(0); // actual value does not matter
2145			}
2146			dos.flush();
2147			int lengthRead = 0;
2148			try {
2149				ObjectInputStream ois = new ObjectInputStream(
2150						new ByteArrayInputStream(out.toByteArray()));
2151				Object obj = ois.readObject();
2152			} catch (OptionalDataException e) {
2153				lengthRead = e.length;
2154			}
2155			assertTrue("Did not throw exception with optional data size ",
2156					length == lengthRead);
2157		} catch (ClassNotFoundException e) {
2158			fail("Unable to read BLOCKDATA: " + e.getMessage());
2159		} catch (IOException e) {
2160			fail("IOException testing BLOCKDATA : " + e.getMessage());
2161		} catch (Error err) {
2162			System.out.println("Error " + err + " when testing BLOCKDATA");
2163			throw err;
2164		}
2165	}
2166}
2167