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;
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)
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 ();
}
};
{
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. */
}
}
- 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
{
}
}
- 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
{
}
}
- 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
{
}
}
- 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
{
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