]> gcc.gnu.org Git - gcc.git/commitdiff
More for PR libgcj/11737:
authorTom Tromey <tromey@redhat.com>
Fri, 1 Aug 2003 03:34:52 +0000 (03:34 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Fri, 1 Aug 2003 03:34:52 +0000 (03:34 +0000)
* java/io/ObjectInputStream.java (processResolution): Use
getMethod.
(getMethod): Make method accessible.
(getField): Make field accessible.
(setBooleanField): Don't call setAccessible here.
(setByteField, setCharField, setDoubleField, setFloatField,
setIntField, setLongField, setShortField, setObjectField):
Likewise.
(callReadMethod): Don't check whether method is null.  Catch
NoSuchMethodException.
* java/io/ObjectOutputStream.java (callWriteMethod): Initialize
cause on thrown exceptions.

From-SVN: r70038

libjava/ChangeLog
libjava/java/io/ObjectInputStream.java
libjava/java/io/ObjectOutputStream.java

index e834b7330f72b4d9945b14eea1dcfd775ff16be9..6ee557e0e42efcbdec1c4ca9021aeccdaf238528 100644 (file)
@@ -1,3 +1,19 @@
+2003-07-31  Tom Tromey  <tromey@redhat.com>
+
+       More for PR libgcj/11737:
+       * java/io/ObjectInputStream.java (processResolution): Use
+       getMethod.
+       (getMethod): Make method accessible.
+       (getField): Make field accessible.
+       (setBooleanField): Don't call setAccessible here.
+       (setByteField, setCharField, setDoubleField, setFloatField,
+       setIntField, setLongField, setShortField, setObjectField):
+       Likewise.
+       (callReadMethod): Don't check whether method is null.  Catch
+       NoSuchMethodException.
+       * java/io/ObjectOutputStream.java (callWriteMethod): Initialize
+       cause on thrown exceptions.
+
 2003-07-31  Stepan Koltsov  <yozh@mx1.ru>
 
        Fix for PR libgcj/11728:
index ef79727c1e112d9e3db3f0f1ea154fb81f89d6ff..918626905a4ff4e9becfc1a6e7fbf51f6e195f55 100644 (file)
@@ -41,10 +41,13 @@ package java.io;
 import java.lang.reflect.Array;
 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;
@@ -1075,9 +1078,7 @@ public class ObjectInputStream extends InputStream
        try
          {
            Class classArgs[] = {};
-           m = obj.getClass ().getDeclaredMethod ("readResolve", classArgs);
-           // m can't be null by definition since an exception would
-           // have been thrown so a check for null is not needed.
+           m = getMethod(obj.getClass(), "readResolve", classArgs);
            obj = m.invoke (obj, new Object[] {});      
          }
        catch (NoSuchMethodException ignore)
@@ -1416,13 +1417,31 @@ public class ObjectInputStream extends InputStream
   private static Field getField (Class klass, String name)
     throws java.lang.NoSuchFieldException
   {
-    return klass.getDeclaredField(name);
+    final Field f = klass.getDeclaredField(name);
+    AccessController.doPrivileged(new PrivilegedAction()
+      {
+       public Object run()
+       {
+         f.setAccessible(true);
+         return null;
+       }
+      });
+    return f;
   }
 
   private static Method getMethod (Class klass, String name, Class args[])
     throws java.lang.NoSuchMethodException
   {
-    return klass.getDeclaredMethod(name, args);
+    final Method m = klass.getDeclaredMethod(name, args);
+    AccessController.doPrivileged(new PrivilegedAction()
+      {
+       public Object run()
+       {
+         m.setAccessible(true);
+         return null;
+       }
+      });
+    return m;
   }
 
   private void callReadMethod (Object obj, ObjectStreamClass osc) throws IOException
@@ -1432,11 +1451,13 @@ public class ObjectInputStream extends InputStream
       {
        Class classArgs[] = {ObjectInputStream.class};
        Method m = getMethod (klass, "readObject", classArgs);
-       if (m == null)
-         return;
        Object args[] = {this};
        m.invoke (obj, args);
       }
+    catch (NoSuchMethodException nsme)
+      {
+       // Nothing.
+      }
     catch (InvocationTargetException x)
       {
         /* Rethrow if possible. */
@@ -1467,7 +1488,6 @@ public class ObjectInputStream extends InputStream
     try
       {
        Field f = getField (klass, field_name);
-       f.setAccessible(true);
        f.setBoolean (obj, val);
       }
     catch (Exception _)
@@ -1481,7 +1501,6 @@ public class ObjectInputStream extends InputStream
     try
       {
        Field f = getField (klass, field_name);
-       f.setAccessible(true);
        f.setByte (obj, val);
       }
     catch (Exception _)
@@ -1495,7 +1514,6 @@ public class ObjectInputStream extends InputStream
     try
       {
        Field f = getField (klass, field_name);
-       f.setAccessible(true);
        f.setChar (obj, val);
       }
     catch (Exception _)
@@ -1509,7 +1527,6 @@ public class ObjectInputStream extends InputStream
     try
       {
        Field f = getField (klass, field_name);
-       f.setAccessible(true);
        f.setDouble (obj, val);
       }
     catch (Exception _)
@@ -1523,7 +1540,6 @@ public class ObjectInputStream extends InputStream
     try
       {
        Field f = getField (klass, field_name);
-       f.setAccessible(true);
        f.setFloat (obj, val);
       }
     catch (Exception _)
@@ -1537,7 +1553,6 @@ public class ObjectInputStream extends InputStream
     try
       {
        Field f = getField (klass, field_name);
-       f.setAccessible(true);
        f.setInt (obj, val);
       }
     catch (Exception _)
@@ -1552,7 +1567,6 @@ public class ObjectInputStream extends InputStream
     try
       {
        Field f = getField (klass, field_name);
-       f.setAccessible(true);
        f.setLong (obj, val);
       }
     catch (Exception _)
@@ -1567,7 +1581,6 @@ public class ObjectInputStream extends InputStream
     try
       {
        Field f = getField (klass, field_name);
-       f.setAccessible(true);
        f.setShort (obj, val);
       }
     catch (Exception _)
@@ -1576,13 +1589,12 @@ public class ObjectInputStream extends InputStream
   }
 
 
-  private void setObjectField (Object obj, Class klass, String field_name, String type_code,
-                              Object val)
+  private void setObjectField (Object obj, Class klass, String field_name,
+                              String type_code, Object val)
   {
     try
       {
        Field f = getField (klass, field_name);
-       f.setAccessible(true);
        // FIXME: We should check the type_code here
        f.set (obj, val);
       }
index 49cb636ee0df9dcc4bab9b319b4853d4cefe7d01..1437a4f69186a0701336386ef85e00bc06cfa078 100644 (file)
@@ -1197,7 +1197,8 @@ public class ObjectOutputStream extends OutputStream
   }
 
 
-  private void callWriteMethod (Object obj, ObjectStreamClass osc) throws IOException
+  private void callWriteMethod (Object obj, ObjectStreamClass osc)
+    throws IOException
   {
     Class klass = osc.forClass();
     try
@@ -1220,13 +1221,19 @@ public class ObjectOutputStream extends OutputStream
        if (exception instanceof IOException)
          throw (IOException) exception;
 
-       throw new IOException ("Exception thrown from writeObject() on " +
-                              klass + ": " + exception.getClass().getName());
+       IOException ioe
+         = new IOException ("Exception thrown from writeObject() on " +
+                            klass + ": " + exception.getClass().getName());
+       ioe.initCause(exception);
+       throw ioe;
       }
     catch (Exception x)
       {
-       throw new IOException ("Failure invoking writeObject() on " +
-                              klass + ": " + x.getClass().getName());
+       IOException ioe
+         = new IOException ("Failure invoking writeObject() on " +
+                            klass + ": " + x.getClass().getName());
+       ioe.initCause(x);
+       throw ioe;
       }
   }
 
This page took 0.074901 seconds and 5 git commands to generate.