if ((replacementEnabled || obj instanceof Replaceable)
if ((replacementEnabled || obj instanceof Serializable)
  public final void writeObject (Object obj) throws IOException  {    if (useSubclassMethod)    {      writeObjectOverride (obj);      return;    }    boolean was_serializing = isSerializing;    if (! was_serializing)      setBlockDataMode (false);    try    {      isSerializing = true;      boolean replaceDone = false;      drain ();      while (true)      {	if (obj == null)	{	  realOutput.writeByte (TC_NULL);	  break;	}	Integer handle = findHandle (obj);	if (handle != null)	{	  realOutput.writeByte (TC_REFERENCE);	  realOutput.writeInt (handle.intValue ());	  break;	}	if (obj instanceof Class)	{	  realOutput.writeByte (TC_CLASS);	  writeObject (ObjectStreamClass.lookup ((Class)obj));	  assignNewHandle (obj);	  break;	}	if (obj instanceof ObjectStreamClass)	{	  ObjectStreamClass osc = (ObjectStreamClass)obj;	  realOutput.writeByte (TC_CLASSDESC);	  realOutput.writeUTF (osc.getName ());	  realOutput.writeLong (osc.getSerialVersionUID ());	  assignNewHandle (obj);	  int flags = osc.getFlags ();	  if (protocolVersion == PROTOCOL_VERSION_2	      && osc.isExternalizable ())	    flags |= SC_BLOCK_DATA;	  realOutput.writeByte (flags);	  ObjectStreamField[] fields = osc.fields;	  realOutput.writeShort (fields.length);	  ObjectStreamField field;	  for (int i=0; i < fields.length; i++)	  {	    field = fields[i];	    realOutput.writeByte (field.getTypeCode ());	    realOutput.writeUTF (field.getName ());	    if (! field.isPrimitive ())	      writeObject (field.getTypeString ());	  }	  setBlockDataMode (true);	  annotateClass (osc.forClass ());	  setBlockDataMode (false);	  realOutput.writeByte (TC_ENDBLOCKDATA);	  if (osc.isSerializable ())	    writeObject (osc.getSuper ());	  else	    writeObject (null);	  break;	}	Object replacedObject = null;	if ((replacementEnabled || obj instanceof Replaceable)	    && ! replaceDone)	{	  replacedObject = obj;	  if (obj instanceof Replaceable)	    obj = ((Replaceable)obj).writeReplace ();	  if (replacementEnabled)	    obj = replaceObject (obj);	  replaceDone = true;	  continue;	}	if (obj instanceof String)	{	  realOutput.writeByte (TC_STRING);	  assignNewHandle (obj);	  realOutput.writeUTF ((String)obj);	  break;	}	Class clazz = obj.getClass ();	ObjectStreamClass osc = ObjectStreamClass.lookup (clazz);	if (osc == null)	  throw new NotSerializableException (clazz.getName ());	if (clazz.isArray ())	{	  realOutput.writeByte (TC_ARRAY);	  writeObject (osc);	  assignNewHandle (obj);	  writeArraySizeAndElements (obj, clazz.getComponentType ());	  break;	}	realOutput.writeByte (TC_OBJECT);	writeObject (osc);	if (replaceDone)	  assignNewHandle (replacedObject);	else	  assignNewHandle (obj);	if (obj instanceof Externalizable)	{	  if (protocolVersion == PROTOCOL_VERSION_2)	    setBlockDataMode (true);	  ((Externalizable)obj).writeExternal (this);	  if (protocolVersion == PROTOCOL_VERSION_2)	  {	    setBlockDataMode (false);	    drain ();	  }	  break;	}	if (obj instanceof Serializable)	{	  currentObject = obj;	  ObjectStreamClass[] hierarchy =	    ObjectStreamClass.getObjectStreamClasses (clazz);	  boolean has_write;	  for (int i=0; i < hierarchy.length; i++)	  {	    currentObjectStreamClass = hierarchy[i];	    fieldsAlreadyWritten = false;	    has_write = currentObjectStreamClass.hasWriteMethod ();	    writeFields (obj, currentObjectStreamClass.fields,			 has_write);	    if (has_write)	    {	      drain ();	      realOutput.writeByte (TC_ENDBLOCKDATA);	    }	  }	  currentObject = null;	  currentObjectStreamClass = null;	  currentPutField = null;	  break;	}	throw new NotSerializableException (clazz.getName ());      } // end pseudo-loop    }    catch (IOException e)    {      realOutput.writeByte (TC_EXCEPTION);      reset (true);      try      {	writeObject (e);      }      catch (IOException ioe)      {	throw new StreamCorruptedException ("Exception " + ioe + " thrown while exception was being written to stream.");      }      reset (true);    }    finally    {      isSerializing = was_serializing;      if (! was_serializing)	setBlockDataMode (true);    }  }