+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:
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;
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)
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
{
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. */
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setBoolean (obj, val);
}
catch (Exception _)
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setByte (obj, val);
}
catch (Exception _)
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setChar (obj, val);
}
catch (Exception _)
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setDouble (obj, val);
}
catch (Exception _)
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setFloat (obj, val);
}
catch (Exception _)
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setInt (obj, val);
}
catch (Exception _)
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setLong (obj, val);
}
catch (Exception _)
try
{
Field f = getField (klass, field_name);
- f.setAccessible(true);
f.setShort (obj, val);
}
catch (Exception _)
}
- 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);
}
}
- private void callWriteMethod (Object obj, ObjectStreamClass osc) throws IOException
+ private void callWriteMethod (Object obj, ObjectStreamClass osc)
+ throws IOException
{
Class klass = osc.forClass();
try
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;
}
}