Patch: FYI: PR 11737 followup patch
Tom Tromey
tromey@redhat.com
Fri Aug 1 04:39:00 GMT 2003
I'm checking this in on the trunk.
My previous PR 11737 patch got us a bit further; this one, in
conjunction with the 11728 fix, lets us correctly run the whole
program. Basically, we need to apply a similar fix to the input side
of serialization.
Tom
Index: ChangeLog
from 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.
Index: java/io/ObjectInputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/ObjectInputStream.java,v
retrieving revision 1.19
diff -u -r1.19 ObjectInputStream.java
--- java/io/ObjectInputStream.java 25 Jun 2003 06:31:58 -0000 1.19
+++ java/io/ObjectInputStream.java 1 Aug 2003 03:32:53 -0000
@@ -41,10 +41,13 @@
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 @@
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 @@
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 @@
{
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 @@
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setBoolean (obj, val);
}
catch (Exception _)
@@ -1481,7 +1501,6 @@
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setByte (obj, val);
}
catch (Exception _)
@@ -1495,7 +1514,6 @@
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setChar (obj, val);
}
catch (Exception _)
@@ -1509,7 +1527,6 @@
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setDouble (obj, val);
}
catch (Exception _)
@@ -1523,7 +1540,6 @@
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setFloat (obj, val);
}
catch (Exception _)
@@ -1537,7 +1553,6 @@
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setInt (obj, val);
}
catch (Exception _)
@@ -1552,7 +1567,6 @@
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setLong (obj, val);
}
catch (Exception _)
@@ -1567,7 +1581,6 @@
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setShort (obj, val);
}
catch (Exception _)
@@ -1576,13 +1589,12 @@
}
- 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: java/io/ObjectOutputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/ObjectOutputStream.java,v
retrieving revision 1.18
diff -u -r1.18 ObjectOutputStream.java
--- java/io/ObjectOutputStream.java 1 Aug 2003 03:02:00 -0000 1.18
+++ java/io/ObjectOutputStream.java 1 Aug 2003 03:32:54 -0000
@@ -1197,7 +1197,8 @@
}
- 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 @@
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;
}
}
More information about the Java-patches
mailing list