public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix debugging dumps for Proxies
@ 2007-04-16 15:28 Andrew Haley
  0 siblings, 0 replies; only message in thread
From: Andrew Haley @ 2007-04-16 15:28 UTC (permalink / raw)
  To: classpath-patches, java-patches

The Object{Input,Ouput}Stream classes have debugging dumps that cause
errors when used on a stream that contains Proxies.  This workaround
prints the proxy class (rather than the object istself) when the
serialized object is a proxy.

Andrew.


2007-04-16  Andrew Haley  <aph@redhat.com>

	* java/io/ObjectInputStream.java: (parseContent):  Call (String,
	Object) version of dumpElementln.
	(dumpElementln(String, Object)): New method.
	* java/io/ObjectOutputStream.java (writeObject): Call (String,
	Object) version of dumpElementln.
	(dumpElementln(String, Object)): New method.

Index: classpath/java/io/ObjectOutputStream.java
===================================================================
--- classpath/java/io/ObjectOutputStream.java	(revision 123861)
+++ classpath/java/io/ObjectOutputStream.java	(working copy)
@@ -191,7 +191,7 @@
       }
 
     if (dump)
-      dumpElementln ("WRITE: " + obj);
+      dumpElementln ("WRITE: ", obj);
     
     depth += 2;    
 
@@ -352,18 +352,18 @@
 		    if (currentObjectStreamClass.hasWriteMethod())
 		      {
 			if (dump)
-			  dumpElementln ("WRITE METHOD CALLED FOR: " + obj);
+			  dumpElementln ("WRITE METHOD CALLED FOR: ", obj);
 			setBlockDataMode(true);
 			callWriteMethod(obj, currentObjectStreamClass);
 			setBlockDataMode(false);
 			realOutput.writeByte(TC_ENDBLOCKDATA);
 			if (dump)
-			  dumpElementln ("WRITE ENDBLOCKDATA FOR: " + obj);
+			  dumpElementln ("WRITE ENDBLOCKDATA FOR: ", obj);
 		      }
 		    else
 		      {
 			if (dump)
-			  dumpElementln ("WRITE FIELDS CALLED FOR: " + obj);
+			  dumpElementln ("WRITE FIELDS CALLED FOR: ", obj);
 			writeFields(obj, currentObjectStreamClass);
 		      }
 		  }
@@ -420,7 +420,7 @@
 	depth -= 2;
 
 	if (dump)
-	  dumpElementln ("END: " + obj);
+	  dumpElementln ("END: ", obj);
       }
   }
 
@@ -1340,6 +1340,28 @@
       }
   }
 
+  private void dumpElementln (String msg, Object obj)
+  {
+    try
+      {
+	for (int i = 0; i < depth; i++)
+	  System.out.print (" ");
+	System.out.print (Thread.currentThread() + ": ");
+	System.out.print (msg);
+	if (java.lang.reflect.Proxy.isProxyClass(obj.getClass()))
+	  System.out.print (obj.getClass());
+	else
+	  System.out.print (obj);
+      }
+    catch (Exception _)
+      {
+      }
+    finally
+      {
+	System.out.println ();
+      }
+  }
+
   private void dumpElementln (String msg)
   {
     for (int i = 0; i < depth; i++)
Index: classpath/java/io/ObjectInputStream.java
===================================================================
--- classpath/java/io/ObjectInputStream.java	(revision 123861)
+++ classpath/java/io/ObjectInputStream.java	(working copy)
@@ -307,7 +307,7 @@
  	  readArrayElements(array, componentType);
  	  if(dump)
  	    for (int i = 0, len = Array.getLength(array); i < len; i++)
- 	      dumpElementln("  ELEMENT[" + i + "]=" + Array.get(array, i));
+ 	      dumpElementln("  ELEMENT[" + i + "]=", Array.get(array, i));
  	  ret_val = processResolution(null, array, handle);
  	  break;
  	}
@@ -1984,6 +1984,24 @@
     System.out.print (Thread.currentThread() + ": ");
   }
 
+  private void dumpElementln (String msg, Object obj)
+  {
+    try
+      {
+	System.out.print(msg);
+	if (java.lang.reflect.Proxy.isProxyClass(obj.getClass()))
+	  System.out.println(obj.getClass());
+	else
+	System.out.println(obj);
+      }
+    catch (Exception _)
+      {
+      }
+    for (int i = 0; i < depth; i++)
+      System.out.print (" ");
+    System.out.print (Thread.currentThread() + ": ");
+  }
+
   // used to keep a prioritized list of object validators
   private static final class ValidatorAndPriority implements Comparable
   {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-04-16 15:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-16 15:28 Fix debugging dumps for Proxies Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).