Hi,

I committed the attached patch to pass or initialize causes for all
exceptions and to remove some bogus code from readClassDescriptor.

I also added a comment to readFields.GetField.getField that it should be
rewritten, the current code is *totally* incomprehensible. (Including
the anti-pattern "return from finally".)

Regards,
Jeroen

2005-08-06  Jeroen Frijters  <[EMAIL PROTECTED]>

        * java/io/ObjectInputStream.java
        (readClassDescriptor): Removed bogus handling of primitive
types.
        (readFields.GetField.defaulted): Pass cause to exception.
        (readFields.GetField.getField): Pass cause to exception.
        (newObject, callReadMethod): Call initCause on exception.
Index: java/io/ObjectInputStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/ObjectInputStream.java,v
retrieving revision 1.60
diff -u -r1.60 ObjectInputStream.java
--- java/io/ObjectInputStream.java      5 Aug 2005 08:28:17 -0000       1.60
+++ java/io/ObjectInputStream.java      7 Aug 2005 12:15:12 -0000
@@ -528,36 +528,7 @@
              
     /* Now that fields have been read we may resolve the class
      * (and read annotation if needed). */
-    Class clazz;
-    try
-      {
-       clazz = resolveClass(osc);
-      }
-    catch (ClassNotFoundException cnfe)
-      {
-       // Maybe it was an primitive class?
-       if (name.equals("void"))
-         clazz = Void.TYPE;
-       else if (name.equals("boolean"))
-         clazz = Boolean.TYPE;
-       else if (name.equals("byte"))
-         clazz = Byte.TYPE;
-       else if (name.equals("short"))
-         clazz = Short.TYPE;
-       else if (name.equals("char"))
-         clazz = Character.TYPE;
-       else if (name.equals("int"))
-         clazz = Integer.TYPE;
-       else if (name.equals("long"))
-         clazz = Long.TYPE;
-       else if (name.equals("float"))
-         clazz = Float.TYPE;
-       else if (name.equals("double"))
-         clazz = Double.TYPE;
-       else
-         throw cnfe;
-      }
-
+    Class clazz = resolveClass(osc);
     boolean oldmode = setBlockDataMode(true);
     osc.setClass(clazz, lookupClass(clazz.getSuperclass()));
     classLookupTable.put(clazz, osc);
@@ -1275,7 +1246,7 @@
            }
          catch (NoSuchFieldException e)
            {
-             throw new IllegalArgumentException(e.getMessage());
+             throw new IllegalArgumentException(e);
            }
        }
 
@@ -1420,6 +1391,7 @@
          ObjectStreamField field = clazz.getField(name);
          boolean illegal = false;
 
+          // XXX This code is horrible and needs to be rewritten!
          try
            {
              try
@@ -1479,7 +1451,7 @@
              catch (NoSuchFieldException e)
                {
                  if (field == null)
-                   throw new IllegalArgumentException(e.getMessage());
+                   throw new IllegalArgumentException(e);
                }
               
            }
@@ -1823,8 +1795,8 @@
       }
     catch (InstantiationException e)
       {
-        throw new ClassNotFoundException
-               ("Instance of " + real_class + " could not be created");
+        throw (ClassNotFoundException) new ClassNotFoundException
+          ("Instance of " + real_class + " could not be created").initCause(e);
       }
   }
 
@@ -1865,13 +1837,13 @@
         if (exception instanceof ClassNotFoundException)
           throw (ClassNotFoundException) exception;
 
-       throw new IOException("Exception thrown from readObject() on " +
-                              klass + ": " + exception.getClass().getName());
+       throw (IOException) new IOException(
+         "Exception thrown from readObject() on " + klass).initCause(x);
       }
     catch (Exception x)
       {
-       throw new IOException("Failure invoking readObject() on " +
-                              klass + ": " + x.getClass().getName());
+       throw (IOException) new IOException(
+         "Failure invoking readObject() on " + klass).initCause(x);
       }
 
     // Invalidate fields which has been read through readFields.
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to