mirror of
git://gcc.gnu.org/git/gcc.git
synced 2024-12-18 15:19:43 +08:00
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. From-SVN: r70038
This commit is contained in:
parent
e14c33e5af
commit
e9c00e62d0
@ -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:
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user