]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libgcj/11737 (java.io.ObjectOutputStream.writeObject does not work with HashMap)
authorTom Tromey <tromey@redhat.com>
Fri, 1 Aug 2003 03:02:00 +0000 (03:02 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Fri, 1 Aug 2003 03:02:00 +0000 (03:02 +0000)
Fix for PR libgcj/11737:
* java/io/ObjectOutputStream.java (getMethod): Make method
accessible.
(getField): Likewise.
(writeObject): Use getMethod.
Import PrivilegedAction and AccessController.
(callWriteMethod): Don't check whether m is null.  Catch
NoSuchMethodException.

From-SVN: r70035

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

index 68db53c6a713e0c35b5fb7e7f3da6fe836f63eee..573b9836ee3205dfcc4629754cea99a0290291ba 100644 (file)
@@ -1,5 +1,14 @@
 2003-07-31  Tom Tromey  <tromey@redhat.com>
 
+       Fix for PR libgcj/11737:
+       * java/io/ObjectOutputStream.java (getMethod): Make method
+       accessible.
+       (getField): Likewise.
+       (writeObject): Use getMethod.
+       Import PrivilegedAction and AccessController.
+       (callWriteMethod): Don't check whether m is null.  Catch
+       NoSuchMethodException.
+
        * java/awt/geom/Arc2D.java (getBounds2D): Implement.
        (containsAngle): Likewise.
        (getStartPoint): Rewrote.
index 4014fcd3dc2d775fbc9a75833d382a3c6a95ccdb..49cb636ee0df9dcc4bab9b319b4853d4cefe7d01 100644 (file)
@@ -42,6 +42,8 @@ import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.InvocationTargetException;
+import java.security.PrivilegedAction;
+import java.security.AccessController;
 import java.util.Hashtable;
 
 import gnu.java.io.ObjectIdentityWrapper;
@@ -240,10 +242,11 @@ public class ObjectOutputStream extends OutputStream
                    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.
+                       m = getMethod(obj.getClass(), "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)
@@ -993,7 +996,8 @@ public class ObjectOutputStream extends OutputStream
        private void checkType (ObjectStreamField field, char type)
          throws IllegalArgumentException
        {
-         if (TypeSignature.getEncodingOfClass (field.getType ()).charAt (0) != type)
+         if (TypeSignature.getEncodingOfClass (field.getType ()).charAt (0)
+             != type)
            throw new IllegalArgumentException ();
        }
       };
@@ -1200,11 +1204,13 @@ public class ObjectOutputStream extends OutputStream
       {
        Class classArgs[] = {ObjectOutputStream.class};
        Method m = getMethod (klass, "writeObject", classArgs);
-       if (m == null)
-         return;
        Object args[] = {this};
        m.invoke (obj, args);   
       }
+    catch (NoSuchMethodException nsme)
+      {
+       // Nothing.
+      }
     catch (InvocationTargetException x)
       {
         /* Rethrow if possible. */
@@ -1239,7 +1245,8 @@ public class ObjectOutputStream extends OutputStream
       }    
   }
 
-  private byte getByteField (Object obj, Class klass, String field_name) throws IOException
+  private byte getByteField (Object obj, Class klass, String field_name)
+    throws IOException
   {
     try
       {
@@ -1253,7 +1260,8 @@ public class ObjectOutputStream extends OutputStream
       }    
   }
 
-  private char getCharField (Object obj, Class klass, String field_name) throws IOException
+  private char getCharField (Object obj, Class klass, String field_name)
+    throws IOException
   {
     try
       {
@@ -1297,7 +1305,8 @@ public class ObjectOutputStream extends OutputStream
       }    
   }
 
-  private int getIntField (Object obj, Class klass, String field_name) throws IOException
+  private int getIntField (Object obj, Class klass, String field_name)
+    throws IOException
   {
     try
       {
@@ -1311,7 +1320,8 @@ public class ObjectOutputStream extends OutputStream
       }    
   }
 
-  private long getLongField (Object obj, Class klass, String field_name) throws IOException
+  private long getLongField (Object obj, Class klass, String field_name)
+    throws IOException
   {
     try
       {
@@ -1359,13 +1369,31 @@ public class ObjectOutputStream extends OutputStream
   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;
   }
 
   // this value comes from 1.2 spec, but is used in 1.1 as well