Commit e9c00e62 by Tom Tromey Committed by Tom Tromey

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
parent e14c33e5
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> 2003-07-31 Stepan Koltsov <yozh@mx1.ru>
Fix for PR libgcj/11728: Fix for PR libgcj/11728:
......
...@@ -41,10 +41,13 @@ package java.io; ...@@ -41,10 +41,13 @@ package java.io;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.security.PrivilegedAction;
import java.security.AccessController;
import java.util.Arrays; import java.util.Arrays;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
import gnu.java.io.ObjectIdentityWrapper; import gnu.java.io.ObjectIdentityWrapper;
import gnu.java.lang.reflect.TypeSignature; import gnu.java.lang.reflect.TypeSignature;
import java.lang.reflect.Field; import java.lang.reflect.Field;
...@@ -1075,9 +1078,7 @@ public class ObjectInputStream extends InputStream ...@@ -1075,9 +1078,7 @@ public class ObjectInputStream extends InputStream
try try
{ {
Class classArgs[] = {}; Class classArgs[] = {};
m = obj.getClass ().getDeclaredMethod ("readResolve", classArgs); m = getMethod(obj.getClass(), "readResolve", 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[] {}); obj = m.invoke (obj, new Object[] {});
} }
catch (NoSuchMethodException ignore) catch (NoSuchMethodException ignore)
...@@ -1416,13 +1417,31 @@ public class ObjectInputStream extends InputStream ...@@ -1416,13 +1417,31 @@ public class ObjectInputStream extends InputStream
private static Field getField (Class klass, String name) private static Field getField (Class klass, String name)
throws java.lang.NoSuchFieldException 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[]) private static Method getMethod (Class klass, String name, Class args[])
throws java.lang.NoSuchMethodException 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 private void callReadMethod (Object obj, ObjectStreamClass osc) throws IOException
...@@ -1432,11 +1451,13 @@ public class ObjectInputStream extends InputStream ...@@ -1432,11 +1451,13 @@ public class ObjectInputStream extends InputStream
{ {
Class classArgs[] = {ObjectInputStream.class}; Class classArgs[] = {ObjectInputStream.class};
Method m = getMethod (klass, "readObject", classArgs); Method m = getMethod (klass, "readObject", classArgs);
if (m == null)
return;
Object args[] = {this}; Object args[] = {this};
m.invoke (obj, args); m.invoke (obj, args);
} }
catch (NoSuchMethodException nsme)
{
// Nothing.
}
catch (InvocationTargetException x) catch (InvocationTargetException x)
{ {
/* Rethrow if possible. */ /* Rethrow if possible. */
...@@ -1467,7 +1488,6 @@ public class ObjectInputStream extends InputStream ...@@ -1467,7 +1488,6 @@ public class ObjectInputStream extends InputStream
try try
{ {
Field f = getField (klass, field_name); Field f = getField (klass, field_name);
f.setAccessible(true);
f.setBoolean (obj, val); f.setBoolean (obj, val);
} }
catch (Exception _) catch (Exception _)
...@@ -1481,7 +1501,6 @@ public class ObjectInputStream extends InputStream ...@@ -1481,7 +1501,6 @@ public class ObjectInputStream extends InputStream
try try
{ {
Field f = getField (klass, field_name); Field f = getField (klass, field_name);
f.setAccessible(true);
f.setByte (obj, val); f.setByte (obj, val);
} }
catch (Exception _) catch (Exception _)
...@@ -1495,7 +1514,6 @@ public class ObjectInputStream extends InputStream ...@@ -1495,7 +1514,6 @@ public class ObjectInputStream extends InputStream
try try
{ {
Field f = getField (klass, field_name); Field f = getField (klass, field_name);
f.setAccessible(true);
f.setChar (obj, val); f.setChar (obj, val);
} }
catch (Exception _) catch (Exception _)
...@@ -1509,7 +1527,6 @@ public class ObjectInputStream extends InputStream ...@@ -1509,7 +1527,6 @@ public class ObjectInputStream extends InputStream
try try
{ {
Field f = getField (klass, field_name); Field f = getField (klass, field_name);
f.setAccessible(true);
f.setDouble (obj, val); f.setDouble (obj, val);
} }
catch (Exception _) catch (Exception _)
...@@ -1523,7 +1540,6 @@ public class ObjectInputStream extends InputStream ...@@ -1523,7 +1540,6 @@ public class ObjectInputStream extends InputStream
try try
{ {
Field f = getField (klass, field_name); Field f = getField (klass, field_name);
f.setAccessible(true);
f.setFloat (obj, val); f.setFloat (obj, val);
} }
catch (Exception _) catch (Exception _)
...@@ -1537,7 +1553,6 @@ public class ObjectInputStream extends InputStream ...@@ -1537,7 +1553,6 @@ public class ObjectInputStream extends InputStream
try try
{ {
Field f = getField (klass, field_name); Field f = getField (klass, field_name);
f.setAccessible(true);
f.setInt (obj, val); f.setInt (obj, val);
} }
catch (Exception _) catch (Exception _)
...@@ -1552,7 +1567,6 @@ public class ObjectInputStream extends InputStream ...@@ -1552,7 +1567,6 @@ public class ObjectInputStream extends InputStream
try try
{ {
Field f = getField (klass, field_name); Field f = getField (klass, field_name);
f.setAccessible(true);
f.setLong (obj, val); f.setLong (obj, val);
} }
catch (Exception _) catch (Exception _)
...@@ -1567,7 +1581,6 @@ public class ObjectInputStream extends InputStream ...@@ -1567,7 +1581,6 @@ public class ObjectInputStream extends InputStream
try try
{ {
Field f = getField (klass, field_name); Field f = getField (klass, field_name);
f.setAccessible(true);
f.setShort (obj, val); f.setShort (obj, val);
} }
catch (Exception _) catch (Exception _)
...@@ -1576,13 +1589,12 @@ public class ObjectInputStream extends InputStream ...@@ -1576,13 +1589,12 @@ public class ObjectInputStream extends InputStream
} }
private void setObjectField (Object obj, Class klass, String field_name, String type_code, private void setObjectField (Object obj, Class klass, String field_name,
Object val) String type_code, Object val)
{ {
try try
{ {
Field f = getField (klass, field_name); Field f = getField (klass, field_name);
f.setAccessible(true);
// FIXME: We should check the type_code here // FIXME: We should check the type_code here
f.set (obj, val); f.set (obj, val);
} }
......
...@@ -1197,7 +1197,8 @@ public class ObjectOutputStream extends OutputStream ...@@ -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(); Class klass = osc.forClass();
try try
...@@ -1220,13 +1221,19 @@ public class ObjectOutputStream extends OutputStream ...@@ -1220,13 +1221,19 @@ public class ObjectOutputStream extends OutputStream
if (exception instanceof IOException) if (exception instanceof IOException)
throw (IOException) exception; throw (IOException) exception;
throw new IOException ("Exception thrown from writeObject() on " + IOException ioe
= new IOException ("Exception thrown from writeObject() on " +
klass + ": " + exception.getClass().getName()); klass + ": " + exception.getClass().getName());
ioe.initCause(exception);
throw ioe;
} }
catch (Exception x) catch (Exception x)
{ {
throw new IOException ("Failure invoking writeObject() on " + IOException ioe
= new IOException ("Failure invoking writeObject() on " +
klass + ": " + x.getClass().getName()); klass + ": " + x.getClass().getName());
ioe.initCause(x);
throw ioe;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment