<commit_before>/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package tests.api.java.io;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.NotActiveException;
import java.io.NotSerializableException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import java.io.ObjectStreamField;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Arrays;

public class ObjectOutputStreamTest extends junit.framework.TestCase implements
		Serializable {

	java.io.File f;

	public class SerializableTestHelper implements Serializable {
		public String aField1;

		public String aField2;

		SerializableTestHelper() {
			aField1 = null;
			aField2 = null;
		}

		SerializableTestHelper(String s, String t) {
			aField1 = s;
			aField2 = t;
		}

		private void readObject(ObjectInputStream ois) throws IOException {
			// note aField2 is not read
			try {
				ObjectInputStream.GetField fields = ois.readFields();
				aField1 = (String) fields.get("aField1", "Zap");
			} catch (Exception e) {
			}
		}

		private void writeObject(ObjectOutputStream oos) throws IOException {
			// note aField2 is not written
			ObjectOutputStream.PutField fields = oos.putFields();
			fields.put("aField1", aField1);
			oos.writeFields();
		}

		public String getText1() {
			return aField1;
		}

		public void setText1(String s) {
			aField1 = s;
		}

		public String getText2() {
			return aField2;
		}

		public void setText2(String s) {
			aField2 = s;
		}
	}

	private static class SerializationTest implements java.io.Serializable {
		int anInt = INIT_INT_VALUE;

		public SerializationTest() {
			super();
		}
	}

	private static class SerializationTestSubclass1 extends SerializationTest
			implements Serializable {
		String aString = INIT_STR_VALUE;

		public SerializationTestSubclass1() {
			super();
			// Just to change default superclass init value
			anInt = INIT_INT_VALUE / 2;
		}
	}

	private static class SpecTestSuperClass implements Runnable, Serializable {
		protected java.lang.String instVar;

		public void run() {
		}
	}

	private static class SpecTest extends SpecTestSuperClass implements
			Cloneable, Serializable {
		public java.lang.String instVar1;

		public static java.lang.String staticVar1;

		public static java.lang.String staticVar2;
		{
			instVar1 = "NonStaticInitialValue";
		}
		static {
			staticVar1 = "StaticInitialValue";
			staticVar1 = new String(staticVar1);
		}

		public Object method(Object objParam, Object objParam2) {
			return new Object();
		}

		public boolean method(boolean bParam, Object objParam) {
			return true;
		}

		public boolean method(boolean bParam, Object objParam, Object objParam2) {
			return true;
		}

	}

	private static class SpecTestSubclass extends SpecTest implements
			Serializable {
		public transient java.lang.String transientInstVar = "transientValue";
	}

	private static class ReadWriteObject implements java.io.Serializable {
		public boolean calledWriteObject = false;

		public boolean calledReadObject = false;

		public ReadWriteObject() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			calledReadObject = true;
			in.readObject();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException {
			calledWriteObject = true;
			out.writeObject(FOO);
		}
	}

	private static class PublicReadWriteObject implements java.io.Serializable {
		public boolean calledWriteObject = false;

		public boolean calledReadObject = false;

		public PublicReadWriteObject() {
			super();
		}

		public void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			calledReadObject = true;
			in.readObject();
		}

		public void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException {
			calledWriteObject = true;
			out.writeObject(FOO);
		}
	}

	private static class FieldOrder implements Serializable {
		String aaa1NonPrimitive = "aaa1";

		int bbb1PrimitiveInt = 5;

		boolean aaa2PrimitiveBoolean = true;

		String bbb2NonPrimitive = "bbb2";
	}

	private static class JustReadObject implements java.io.Serializable {
		public boolean calledReadObject = false;

		public JustReadObject() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			calledReadObject = true;
			in.defaultReadObject();
		}
	}

	private static class JustWriteObject implements java.io.Serializable {
		public boolean calledWriteObject = false;

		public JustWriteObject() {
			super();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			calledWriteObject = true;
			out.defaultWriteObject();
		}
	}

	private static class ClassBasedReplacementWhenDumping implements
			java.io.Serializable {
		public boolean calledReplacement = false;

		public ClassBasedReplacementWhenDumping() {
			super();
		}

		private Object writeReplace() {
			calledReplacement = true;
			return FOO; // Replacement is a String
		}
	}

	private static class MultipleClassBasedReplacementWhenDumping implements
			java.io.Serializable {
		private static class C1 implements java.io.Serializable {
			private Object writeReplace() {
				return new C2();
			}
		}

		private static class C2 implements java.io.Serializable {
			private Object writeReplace() {
				return new C3();
			}
		}

		private static class C3 implements java.io.Serializable {
			private Object writeReplace() {
				return FOO;
			}
		}

		public MultipleClassBasedReplacementWhenDumping() {
			super();
		}

		private Object writeReplace() {
			return new C1();
		}
	}

	private static class ClassBasedReplacementWhenLoading implements
			java.io.Serializable {
		public ClassBasedReplacementWhenLoading() {
			super();
		}

		private Object readResolve() {
			return FOO; // Replacement is a String
		}
	}

	private static class ClassBasedReplacementWhenLoadingViolatesFieldType
			implements java.io.Serializable {
		public ClassBasedReplacementWhenLoading classBasedReplacementWhenLoading = new ClassBasedReplacementWhenLoading();

		public ClassBasedReplacementWhenLoadingViolatesFieldType() {
			super();
		}
	}

	private static class MyExceptionWhenDumping implements java.io.Serializable {
		private static class MyException extends java.io.IOException {
		};

		public boolean anInstanceVar = false;

		public MyExceptionWhenDumping() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			in.defaultReadObject();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			throw new MyException();
		}
	}

	private static class NonSerializableExceptionWhenDumping implements
			java.io.Serializable {
		public Object anInstanceVar = new Object();

		public NonSerializableExceptionWhenDumping() {
			super();
		}
	}

	private static class MyUnserializableExceptionWhenDumping implements
			java.io.Serializable {
		private static class MyException extends java.io.IOException {
			private Object notSerializable = new Object();
		};

		public boolean anInstanceVar = false;

		public MyUnserializableExceptionWhenDumping() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			in.defaultReadObject();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			throw new MyException();
		}
	}

	private static class WithUnmatchingSerialPersistentFields implements
			java.io.Serializable {
		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
				"value", String.class) };

		public int anInstanceVar = 5;

		public WithUnmatchingSerialPersistentFields() {
			super();
		}
	}

	private static class WithMatchingSerialPersistentFields implements
			java.io.Serializable {
		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
				"anInstanceVar", String.class) };

		public String anInstanceVar = FOO + FOO;

		public WithMatchingSerialPersistentFields() {
			super();
		}
	}

	private static class SerialPersistentFields implements java.io.Serializable {
		private static final String SIMULATED_FIELD_NAME = "text";

		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
				SIMULATED_FIELD_NAME, String.class) };

		public int anInstanceVar = 5;

		public SerialPersistentFields() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			ObjectInputStream.GetField fields = in.readFields();
			anInstanceVar = Integer.parseInt((String) fields.get(
					SIMULATED_FIELD_NAME, "-5"));
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			ObjectOutputStream.PutField fields = out.putFields();
			fields.put(SIMULATED_FIELD_NAME, Integer.toString(anInstanceVar));
			out.writeFields();
		}
	}

	private static class WriteFieldsWithoutFetchingPutFields implements
			java.io.Serializable {
		private static final String SIMULATED_FIELD_NAME = "text";

		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
				SIMULATED_FIELD_NAME, String.class) };

		public int anInstanceVar = 5;

		public WriteFieldsWithoutFetchingPutFields() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			in.readFields();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			out.writeFields();
		}
	}

	private static class SerialPersistentFieldsWithoutField implements
			java.io.Serializable {
		public int anInstanceVar = 5;

		public SerialPersistentFieldsWithoutField() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			in.readFields();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			out.putFields();
			out.writeFields();
		}
	}

	private static class NotSerializable {
		private int foo;

		public NotSerializable() {
		}

		protected Object writeReplace() throws ObjectStreamException {
			return new Integer(42);
		}
	}

	private static class ExternalizableWithReplace implements Externalizable {
		private int foo;

		public ExternalizableWithReplace() {
		}

		protected Object writeReplace() throws ObjectStreamException {
			return new Integer(42);
		}

		public void writeExternal(ObjectOutput out) {
		}

		public void readExternal(ObjectInput in) {
		}
	}

	protected static final String MODE_XLOAD = "xload";

	protected static final String MODE_XDUMP = "xdump";

	static final String FOO = "foo";

	static final String MSG_WITE_FAILED = "Failed to write: ";

	private static final boolean DEBUG = false;

	protected static boolean xload = false;

	protected static boolean xdump = false;

	protected static String xFileName = null;

	protected ObjectInputStream ois;

	protected ObjectOutputStream oos;

	protected ByteArrayOutputStream bao;

	static final int INIT_INT_VALUE = 7;

	static final String INIT_STR_VALUE = "a string that is blortz";

	/**
	 * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
     */
    public void test_ConstructorLjava_io_OutputStream() throws IOException {
        // Test for method java.io.ObjectOutputStream(java.io.OutputStream)
        oos.close();
        oos = new ObjectOutputStream(new ByteArrayOutputStream());
        oos.close();
    }

	/**
	 * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
	 */
	public void test_ConstructorLjava_io_OutputStream_subtest0() throws IOException {
		System.setSecurityManager(new SecurityManager());
		try {
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			// should not cause SecurityException
			new ObjectOutputStream(out);
			// should not cause SecurityException
			class SubTest1 extends ObjectOutputStream {
				SubTest1(OutputStream out) throws IOException {
					super(out);
				}
			}

			// should not cause SecurityException
			new SubTest1(out);
			class SubTest2 extends ObjectOutputStream {
				SubTest2(OutputStream out) throws IOException {
					super(out);
				}

				public void writeUnshared(Object obj) throws IOException {
				}
			}

            try {
				new SubTest2(out);
				fail("should throw SecurityException 1");
			} catch (SecurityException e) {
			}
			class SubTest3 extends ObjectOutputStream {
				SubTest3(OutputStream out) throws IOException {
					super(out);
				}

				public PutField putFields() throws IOException {
					return null;
				}
			}

			try {
				new SubTest3(out);
				fail("should throw SecurityException 2");
			} catch (SecurityException e) {
			}
		} finally {
			System.setSecurityManager(null);
		}
	}

	/**<commit_msg>Fix test case to make ObjectOutputStreamTest pass on RI<commit_after>/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package tests.api.java.io;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.NotActiveException;
import java.io.NotSerializableException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import java.io.ObjectStreamField;
import java.io.OutputStream;
import java.io.Serializable;
import java.io.SerializablePermission;
import java.security.Permission;
import java.util.Arrays;

public class ObjectOutputStreamTest extends junit.framework.TestCase implements
		Serializable {

	java.io.File f;

	public class SerializableTestHelper implements Serializable {
		public String aField1;

		public String aField2;

		SerializableTestHelper() {
			aField1 = null;
			aField2 = null;
		}

		SerializableTestHelper(String s, String t) {
			aField1 = s;
			aField2 = t;
		}

		private void readObject(ObjectInputStream ois) throws IOException {
			// note aField2 is not read
			try {
				ObjectInputStream.GetField fields = ois.readFields();
				aField1 = (String) fields.get("aField1", "Zap");
			} catch (Exception e) {
			}
		}

		private void writeObject(ObjectOutputStream oos) throws IOException {
			// note aField2 is not written
			ObjectOutputStream.PutField fields = oos.putFields();
			fields.put("aField1", aField1);
			oos.writeFields();
		}

		public String getText1() {
			return aField1;
		}

		public void setText1(String s) {
			aField1 = s;
		}

		public String getText2() {
			return aField2;
		}

		public void setText2(String s) {
			aField2 = s;
		}
	}

	private static class SerializationTest implements java.io.Serializable {
		int anInt = INIT_INT_VALUE;

		public SerializationTest() {
			super();
		}
	}

	private static class SerializationTestSubclass1 extends SerializationTest
			implements Serializable {
		String aString = INIT_STR_VALUE;

		public SerializationTestSubclass1() {
			super();
			// Just to change default superclass init value
			anInt = INIT_INT_VALUE / 2;
		}
	}

	private static class SpecTestSuperClass implements Runnable, Serializable {
		protected java.lang.String instVar;

		public void run() {
		}
	}

	private static class SpecTest extends SpecTestSuperClass implements
			Cloneable, Serializable {
		public java.lang.String instVar1;

		public static java.lang.String staticVar1;

		public static java.lang.String staticVar2;
		{
			instVar1 = "NonStaticInitialValue";
		}
		static {
			staticVar1 = "StaticInitialValue";
			staticVar1 = new String(staticVar1);
		}

		public Object method(Object objParam, Object objParam2) {
			return new Object();
		}

		public boolean method(boolean bParam, Object objParam) {
			return true;
		}

		public boolean method(boolean bParam, Object objParam, Object objParam2) {
			return true;
		}

	}

	private static class SpecTestSubclass extends SpecTest implements
			Serializable {
		public transient java.lang.String transientInstVar = "transientValue";
	}

	private static class ReadWriteObject implements java.io.Serializable {
		public boolean calledWriteObject = false;

		public boolean calledReadObject = false;

		public ReadWriteObject() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			calledReadObject = true;
			in.readObject();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException {
			calledWriteObject = true;
			out.writeObject(FOO);
		}
	}

	private static class PublicReadWriteObject implements java.io.Serializable {
		public boolean calledWriteObject = false;

		public boolean calledReadObject = false;

		public PublicReadWriteObject() {
			super();
		}

		public void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			calledReadObject = true;
			in.readObject();
		}

		public void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException {
			calledWriteObject = true;
			out.writeObject(FOO);
		}
	}

	private static class FieldOrder implements Serializable {
		String aaa1NonPrimitive = "aaa1";

		int bbb1PrimitiveInt = 5;

		boolean aaa2PrimitiveBoolean = true;

		String bbb2NonPrimitive = "bbb2";
	}

	private static class JustReadObject implements java.io.Serializable {
		public boolean calledReadObject = false;

		public JustReadObject() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			calledReadObject = true;
			in.defaultReadObject();
		}
	}

	private static class JustWriteObject implements java.io.Serializable {
		public boolean calledWriteObject = false;

		public JustWriteObject() {
			super();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			calledWriteObject = true;
			out.defaultWriteObject();
		}
	}

	private static class ClassBasedReplacementWhenDumping implements
			java.io.Serializable {
		public boolean calledReplacement = false;

		public ClassBasedReplacementWhenDumping() {
			super();
		}

		private Object writeReplace() {
			calledReplacement = true;
			return FOO; // Replacement is a String
		}
	}

	private static class MultipleClassBasedReplacementWhenDumping implements
			java.io.Serializable {
		private static class C1 implements java.io.Serializable {
			private Object writeReplace() {
				return new C2();
			}
		}

		private static class C2 implements java.io.Serializable {
			private Object writeReplace() {
				return new C3();
			}
		}

		private static class C3 implements java.io.Serializable {
			private Object writeReplace() {
				return FOO;
			}
		}

		public MultipleClassBasedReplacementWhenDumping() {
			super();
		}

		private Object writeReplace() {
			return new C1();
		}
	}

	private static class ClassBasedReplacementWhenLoading implements
			java.io.Serializable {
		public ClassBasedReplacementWhenLoading() {
			super();
		}

		private Object readResolve() {
			return FOO; // Replacement is a String
		}
	}

	private static class ClassBasedReplacementWhenLoadingViolatesFieldType
			implements java.io.Serializable {
		public ClassBasedReplacementWhenLoading classBasedReplacementWhenLoading = new ClassBasedReplacementWhenLoading();

		public ClassBasedReplacementWhenLoadingViolatesFieldType() {
			super();
		}
	}

	private static class MyExceptionWhenDumping implements java.io.Serializable {
		private static class MyException extends java.io.IOException {
		};

		public boolean anInstanceVar = false;

		public MyExceptionWhenDumping() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			in.defaultReadObject();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			throw new MyException();
		}
	}

	private static class NonSerializableExceptionWhenDumping implements
			java.io.Serializable {
		public Object anInstanceVar = new Object();

		public NonSerializableExceptionWhenDumping() {
			super();
		}
	}

	private static class MyUnserializableExceptionWhenDumping implements
			java.io.Serializable {
		private static class MyException extends java.io.IOException {
			private Object notSerializable = new Object();
		};

		public boolean anInstanceVar = false;

		public MyUnserializableExceptionWhenDumping() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			in.defaultReadObject();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			throw new MyException();
		}
	}

	private static class WithUnmatchingSerialPersistentFields implements
			java.io.Serializable {
		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
				"value", String.class) };

		public int anInstanceVar = 5;

		public WithUnmatchingSerialPersistentFields() {
			super();
		}
	}

	private static class WithMatchingSerialPersistentFields implements
			java.io.Serializable {
		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
				"anInstanceVar", String.class) };

		public String anInstanceVar = FOO + FOO;

		public WithMatchingSerialPersistentFields() {
			super();
		}
	}

	private static class SerialPersistentFields implements java.io.Serializable {
		private static final String SIMULATED_FIELD_NAME = "text";

		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
				SIMULATED_FIELD_NAME, String.class) };

		public int anInstanceVar = 5;

		public SerialPersistentFields() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			ObjectInputStream.GetField fields = in.readFields();
			anInstanceVar = Integer.parseInt((String) fields.get(
					SIMULATED_FIELD_NAME, "-5"));
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			ObjectOutputStream.PutField fields = out.putFields();
			fields.put(SIMULATED_FIELD_NAME, Integer.toString(anInstanceVar));
			out.writeFields();
		}
	}

	private static class WriteFieldsWithoutFetchingPutFields implements
			java.io.Serializable {
		private static final String SIMULATED_FIELD_NAME = "text";

		private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
				SIMULATED_FIELD_NAME, String.class) };

		public int anInstanceVar = 5;

		public WriteFieldsWithoutFetchingPutFields() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			in.readFields();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			out.writeFields();
		}
	}

	private static class SerialPersistentFieldsWithoutField implements
			java.io.Serializable {
		public int anInstanceVar = 5;

		public SerialPersistentFieldsWithoutField() {
			super();
		}

		private void readObject(java.io.ObjectInputStream in)
				throws java.io.IOException, ClassNotFoundException {
			in.readFields();
		}

		private void writeObject(java.io.ObjectOutputStream out)
				throws java.io.IOException, ClassNotFoundException {
			out.putFields();
			out.writeFields();
		}
	}

	private static class NotSerializable {
		private int foo;

		public NotSerializable() {
		}

		protected Object writeReplace() throws ObjectStreamException {
			return new Integer(42);
		}
	}

	private static class ExternalizableWithReplace implements Externalizable {
		private int foo;

		public ExternalizableWithReplace() {
		}

		protected Object writeReplace() throws ObjectStreamException {
			return new Integer(42);
		}

		public void writeExternal(ObjectOutput out) {
		}

		public void readExternal(ObjectInput in) {
		}
	}

	protected static final String MODE_XLOAD = "xload";

	protected static final String MODE_XDUMP = "xdump";

	static final String FOO = "foo";

	static final String MSG_WITE_FAILED = "Failed to write: ";

	private static final boolean DEBUG = false;

	protected static boolean xload = false;

	protected static boolean xdump = false;

	protected static String xFileName = null;

	protected ObjectInputStream ois;

	protected ObjectOutputStream oos;

	protected ByteArrayOutputStream bao;

	static final int INIT_INT_VALUE = 7;

	static final String INIT_STR_VALUE = "a string that is blortz";

	/**
	 * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
     */
    public void test_ConstructorLjava_io_OutputStream() throws IOException {
        // Test for method java.io.ObjectOutputStream(java.io.OutputStream)
        oos.close();
        oos = new ObjectOutputStream(new ByteArrayOutputStream());
        oos.close();
    }

	/**
	 * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
	 */
	public void test_ConstructorLjava_io_OutputStream_subtest0() throws IOException {

		// custom security manager
		SecurityManager sm = new SecurityManager() {

			final SerializablePermission forbidenPermission =
				new SerializablePermission("enableSubclassImplementation");

			public void checkPermission(Permission perm) {
				if (forbidenPermission.equals(perm)) {
					throw new SecurityException();
				}
			}
		};

		SecurityManager oldSm = System.getSecurityManager();
		System.setSecurityManager(sm);
		try {
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			// should not cause SecurityException
			new ObjectOutputStream(out);
			// should not cause SecurityException
			class SubTest1 extends ObjectOutputStream {
				SubTest1(OutputStream out) throws IOException {
					super(out);
				}
			}

			// should not cause SecurityException
			new SubTest1(out);
			class SubTest2 extends ObjectOutputStream {
				SubTest2(OutputStream out) throws IOException {
					super(out);
				}

				public void writeUnshared(Object obj) throws IOException {
				}
			}

            try {
				new SubTest2(out);
				fail("should throw SecurityException 1");
			} catch (SecurityException e) {
			}
			class SubTest3 extends ObjectOutputStream {
				SubTest3(OutputStream out) throws IOException {
					super(out);
				}

				public PutField putFields() throws IOException {
					return null;
				}
			}

			try {
				new SubTest3(out);
				fail("should throw SecurityException 2");
			} catch (SecurityException e) {
			}
		} finally {
			System.setSecurityManager(oldSm);
		}
	}

	/**
{'fraction_non_alphanumeric': 0.0795402941279212, 'fraction_numerical': 0.005519265029517589, 'mean_word_length': 4.09939437121482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3874275', 'n_tokens_mistral': 9229, 'n_tokens_neox': 7829, 'n_words': 2173}