For now don't use the generated field accessors unless we're running in a
sandbox. They should work exactly the same but there seem to be remaining niggles, so we'll iron those out without impacting other projects. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4706 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -23,6 +23,7 @@ package com.threerings.io;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.ReflectPermission;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -57,7 +58,8 @@ public abstract class FieldMarshaller
|
|||||||
createMarshallers();
|
createMarshallers();
|
||||||
}
|
}
|
||||||
|
|
||||||
// first look to see if this field has custom reader/writer methods
|
// if necessary (we're running in a sandbox), look for custom field accessors
|
||||||
|
if (useFieldAccessors()) {
|
||||||
Method reader = null, writer = null;
|
Method reader = null, writer = null;
|
||||||
try {
|
try {
|
||||||
reader = field.getDeclaringClass().getMethod(
|
reader = field.getDeclaringClass().getMethod(
|
||||||
@@ -75,6 +77,7 @@ public abstract class FieldMarshaller
|
|||||||
", writer=" + writer + "].");
|
", writer=" + writer + "].");
|
||||||
// fall through to using reflection on the fields...
|
// fall through to using reflection on the fields...
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Class ftype = field.getType();
|
Class ftype = field.getType();
|
||||||
if (ftype.isInterface()) {
|
if (ftype.isInterface()) {
|
||||||
@@ -111,6 +114,23 @@ public abstract class FieldMarshaller
|
|||||||
return "writeField_" + field;
|
return "writeField_" + field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if we should use the generated field marshaller methods that allow us to work
|
||||||
|
* around our inability to read and write protected and private fields of a {@link Streamable}.
|
||||||
|
*/
|
||||||
|
protected static boolean useFieldAccessors ()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
SecurityManager security = System.getSecurityManager();
|
||||||
|
if (security != null) {
|
||||||
|
security.checkPermission(new ReflectPermission("suppressAccessChecks"));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (SecurityException se) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to marshall and unmarshall classes for which we have a basic {@link Streamer}.
|
* Used to marshall and unmarshall classes for which we have a basic {@link Streamer}.
|
||||||
*/
|
*/
|
||||||
@@ -157,7 +177,7 @@ public abstract class FieldMarshaller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses custom reader and writer methods to read and write a field.
|
* Uses custom accessor methods to read and write a field.
|
||||||
*/
|
*/
|
||||||
protected static class MethodFieldMarshaller extends FieldMarshaller
|
protected static class MethodFieldMarshaller extends FieldMarshaller
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user