m = obj.getClass ().getDeclaredMethod ("writeReplace", classArgs);
m = getMethod(obj.getClass(), "writeReplace", classArgs);
  public final void writeObject (Object obj) throws IOException  {    if (useSubclassMethod)      {	writeObjectOverride (obj);	return;      }    boolean was_serializing = isSerializing;    boolean old_mode = setBlockDataMode (false);    try      {	isSerializing = true;	boolean replaceDone = false;	Object replacedObject = null;		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)	      {		Class cl = (Class)obj;		ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject (cl);		assignNewHandle (obj);		realOutput.writeByte (TC_CLASS);		if (!osc.isProxyClass)		  {		    writeObject (osc);		  }		else		  {		    realOutput.writeByte (TC_PROXYCLASSDESC);		    Class[] intfs = cl.getInterfaces();		    realOutput.writeInt(intfs.length);		    for (int i = 0; i < intfs.length; i++)		      realOutput.writeUTF(intfs[i].getName());		    		    boolean oldmode = setBlockDataMode (true);		    annotateProxyClass(cl);		    setBlockDataMode (oldmode);		    realOutput.writeByte(TC_ENDBLOCKDATA);		    		    writeObject (osc.getSuper());		  }		break;	      }	    if (obj instanceof ObjectStreamClass)	      {		writeClassDescriptor ((ObjectStreamClass) obj);		break;	      }	    if ((replacementEnabled || obj instanceof Serializable)		&& ! replaceDone)	      {		replacedObject = obj;		if (obj instanceof Serializable)		  {		    Method m = null;		    try		      {			Class classArgs[] = {};			m = obj.getClass ().getDeclaredMethod ("writeReplace",							       classArgs);			// m can't be null by definition since an exception would			// have been thrown so a check for null is not needed.			obj = m.invoke (obj, new Object[] {});		      }		    catch (NoSuchMethodException ignore)		      {		      }		    catch (IllegalAccessException ignore)		      {		      }		    catch (InvocationTargetException ignore)		      {		      }		  }		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.lookupForClassObject (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);		    realOutput.writeByte (TC_ENDBLOCKDATA);		  }		break;	      }	    if (obj instanceof Serializable)	      {		currentObject = obj;		ObjectStreamClass[] hierarchy =		  ObjectStreamClass.getObjectStreamClasses (clazz);		for (int i=0; i < hierarchy.length; i++)		  {		    currentObjectStreamClass = hierarchy[i];		    fieldsAlreadyWritten = false;		    if (currentObjectStreamClass.hasWriteMethod ())		      {			setBlockDataMode (true);			callWriteMethod (obj, currentObjectStreamClass);			setBlockDataMode (false);			realOutput.writeByte (TC_ENDBLOCKDATA);		      }		    else		      writeFields (obj, currentObjectStreamClass);		  }		currentObject = null;		currentObjectStreamClass = null;		currentPutField = null;		break;	      }	    throw new NotSerializableException (clazz.getName ());	  } // end pseudo-loop      }    catch (ObjectStreamException ose)      {	// Rethrow these are fatal.	throw ose;      }    catch (IOException e)      {	realOutput.writeByte (TC_EXCEPTION);	reset (true);	setBlockDataMode (false);	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;	setBlockDataMode (old_mode);      }  }