ObjectOutputStream.java: Add DEBUG statements everywhere.

2004-06-21  Andrew Haley  <aph@redhat.com>

	* java/io/ObjectOutputStream.java: Add DEBUG statements
	everywhere.
	(dumpElementln): New method.
	(depth): New field.
	* java/io/ObjectInputStream.java
	(currentClassLoader): Make native.
	(callersClassLoader): New field.
	(depth): New field.
	(readObject): ENDBLOCKDATA is generated if the class has a write
	method, not if it has a read method.
	(readObject): Save and restore this.currentObject and
	this.currentObjectStreamClass around calls to callReadMethod().
	* java/io/natObjectInputStream.cc (getCallersClassLoader): New
	method.

From-SVN: r83440
This commit is contained in:
Andrew Haley 2004-06-21 16:52:14 +00:00 committed by Andrew Haley
parent 413ed876c5
commit deb3d52fec
4 changed files with 178 additions and 38 deletions

View file

@ -38,20 +38,24 @@ exception statement from your version. */
package java.io;
import gnu.classpath.Configuration;
import gnu.java.io.ObjectIdentityWrapper;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.security.PrivilegedAction;
import java.security.AccessController;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Vector;
import gnu.java.io.ObjectIdentityWrapper;
import gnu.java.lang.reflect.TypeSignature;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import gnu.classpath.Configuration;
public class ObjectInputStream extends InputStream
implements ObjectInput, ObjectStreamConstants
{
@ -120,6 +124,15 @@ public class ObjectInputStream extends InputStream
*/
public final Object readObject() throws ClassNotFoundException, IOException
{
if (callersClassLoader == null)
{
callersClassLoader = getCallersClassLoader ();
if (Configuration.DEBUG && dump)
{
dumpElementln ("CallersClassLoader = " + callersClassLoader);
}
}
if (this.useSubclassMethod)
return readObjectOverride();
@ -134,6 +147,9 @@ public class ObjectInputStream extends InputStream
this.isDeserializing = true;
byte marker = this.realInputStream.readByte();
depth += 2;
if(dump) dumpElement("MARKER: 0x" + Integer.toHexString(marker) + " ");
try
@ -151,9 +167,9 @@ public class ObjectInputStream extends InputStream
case TC_BLOCKDATALONG:
{
if (marker == TC_BLOCKDATALONG)
if(dump) dumpElementln("BLOCKDATALONG");
{ if(dump) dumpElementln("BLOCKDATALONG"); }
else
if(dump) dumpElementln("BLOCKDATA");
{ if(dump) dumpElementln("BLOCKDATA"); }
readNextBlock(marker);
throw new StreamCorruptedException("Unexpected blockData");
}
@ -319,6 +335,9 @@ public class ObjectInputStream extends InputStream
Object obj = newObject(clazz, osc.firstNonSerializableParent);
int handle = assignNewHandle(obj);
Object prevObject = this.currentObject;
ObjectStreamClass prevObjectStreamClass = this.currentObjectStreamClass;
this.currentObject = obj;
ObjectStreamClass[] hierarchy =
inputGetObjectStreamClasses(clazz);
@ -341,34 +360,42 @@ public class ObjectInputStream extends InputStream
boolean oldmode = setBlockDataMode(true);
callReadMethod(readObjectMethod, this.currentObjectStreamClass.forClass(), obj);
setBlockDataMode(oldmode);
if(dump) dumpElement("ENDBLOCKDATA? ");
try
{
// FIXME: XXX: This try block is to catch EOF which is
// thrown for some objects. That indicates a bug in the logic.
if (this.realInputStream.readByte() != TC_ENDBLOCKDATA)
throw new IOException
("No end of block data seen for class with readObject (ObjectInputStream) method.");
if(dump) dumpElementln("yes");
}
catch (EOFException e)
{
if(dump) dumpElementln("no, got EOFException");
}
catch (IOException e)
{
if(dump) dumpElementln("no, got IOException");
}
}
else
{
readFields(obj, currentObjectStreamClass);
}
if (this.currentObjectStreamClass.hasWriteMethod())
{
if(dump) dumpElement("ENDBLOCKDATA? ");
try
{
// FIXME: XXX: This try block is to
// catch EOF which is thrown for some
// objects. That indicates a bug in
// the logic.
if (this.realInputStream.readByte() != TC_ENDBLOCKDATA)
throw new IOException
("No end of block data seen for class with readObject (ObjectInputStream) method.");
if(dump) dumpElementln("yes");
}
// catch (EOFException e)
// {
// if(dump) dumpElementln("no, got EOFException");
// }
catch (IOException e)
{
if(dump) dumpElementln("no, got IOException");
}
}
}
this.currentObject = null;
this.currentObjectStreamClass = null;
this.currentObject = prevObject;
this.currentObjectStreamClass = prevObjectStreamClass;
ret_val = processResolution(osc, obj, handle);
break;
}
@ -397,6 +424,8 @@ public class ObjectInputStream extends InputStream
this.isDeserializing = was_deserializing;
depth -= 2;
if (! was_deserializing)
{
if (validators.size() > 0)
@ -710,7 +739,7 @@ public class ObjectInputStream extends InputStream
protected Class resolveClass(ObjectStreamClass osc)
throws ClassNotFoundException, IOException
{
return Class.forName(osc.getName(), true, currentLoader());
return Class.forName(osc.getName(), true, callersClassLoader);
}
/**
@ -1802,11 +1831,9 @@ public class ObjectInputStream extends InputStream
* @param sm SecurityManager instance which should be called.
* @return The current class loader in the calling stack.
*/
private static ClassLoader currentClassLoader (SecurityManager sm)
{
// FIXME: This is too simple.
return ClassLoader.getSystemClassLoader ();
}
private static native ClassLoader currentClassLoader (SecurityManager sm);
private native ClassLoader getCallersClassLoader();
private void callReadMethod (Method readObject, Class klass, Object obj) throws IOException
{
@ -1864,6 +1891,11 @@ public class ObjectInputStream extends InputStream
private static boolean dump = false && Configuration.DEBUG;
private ClassLoader callersClassLoader;
// The nesting depth for debugging output
private int depth = 0;
private void dumpElement (String msg)
{
System.out.print(msg);
@ -1872,6 +1904,9 @@ public class ObjectInputStream extends InputStream
private void dumpElementln (String msg)
{
System.out.println(msg);
for (int i = 0; i < depth; i++)
System.out.print (" ");
System.out.print (Thread.currentThread() + ": ");
}
static