Permalink
Browse files

Always setAccessible

  • Loading branch information...
alta189
alta189 committed May 13, 2012
1 parent 31f252a commit e3ebddf93d0df332b0ac73877edb79c2a1d675e0
@@ -41,6 +41,7 @@ public static IdRegistration getId(Class<?> clazz) throws TableRegistrationExcep
// Check if id defaults to 0
try {
Object o = new EmptyInjector().newInstance(clazz);
+ field.setAccessible(true);
int id = ((Number)field.get(o)).intValue();
if (id != 0)
throw new TableRegistrationException("The id does not default to 0");
@@ -65,6 +65,7 @@ public static boolean validClass(Class<?> clazz) {
public static Object deserialize(Class<?> clazz, String data) {
try {
Method deserialize = clazz.getDeclaredMethod("deserialize", String.class);
+ deserialize.setAccessible(true);
return deserialize.invoke(null, data);
} catch (NoSuchMethodException e) {
throw new SerializeException("Could not deserialize data", e.getCause());
@@ -78,6 +79,7 @@ public static Object deserialize(Class<?> clazz, String data) {
public static String serialize(Class<?> clazz, Object object) {
try {
Method serialize = clazz.getDeclaredMethod("serialize");
+ serialize.setAccessible(true);
return (String) serialize.invoke(object);
} catch (NoSuchMethodException e) {
throw new SerializeException("Could not serialize Class '" + clazz.getCanonicalName() + "'", e.getCause());
@@ -25,6 +25,7 @@ public static int getIdValue(TableRegistration table, Object o) {
IdRegistration idRegistration = table.getId();
try {
Field field = o.getClass().getDeclaredField(idRegistration.getName());
+ field.setAccessible(true);
return ((Number)field.get(o)).intValue();
} catch (NoSuchFieldException e) {
throw new IllegalArgumentException(e);
@@ -36,6 +37,7 @@ public static int getIdValue(TableRegistration table, Object o) {
public static Integer getValueAsInteger(FieldRegistration fieldRegistration, Object o) {
try {
Field field = o.getClass().getDeclaredField(fieldRegistration.getName());
+ field.setAccessible(true);
return field.getInt(o);
} catch (Exception e) {
throw new IllegalArgumentException(e);
@@ -45,6 +47,7 @@ public static Integer getValueAsInteger(FieldRegistration fieldRegistration, Obj
public static Long getValueAsLong(FieldRegistration fieldRegistration, Object o) {
try {
Field field = o.getClass().getDeclaredField(fieldRegistration.getName());
+ field.setAccessible(true);
return field.getLong(o);
} catch (Exception e) {
throw new IllegalArgumentException(e);
@@ -54,6 +57,7 @@ public static Long getValueAsLong(FieldRegistration fieldRegistration, Object o)
public static Double getValueAsDouble(FieldRegistration fieldRegistration, Object o) {
try {
Field field = o.getClass().getDeclaredField(fieldRegistration.getName());
+ field.setAccessible(true);
return field.getDouble(o);
} catch (Exception e) {
throw new IllegalArgumentException(e);
@@ -63,6 +67,7 @@ public static Double getValueAsDouble(FieldRegistration fieldRegistration, Objec
public static String getValueAsString(FieldRegistration fieldRegistration, Object o) {
try {
Field field = o.getClass().getDeclaredField(fieldRegistration.getName());
+ field.setAccessible(true);
return (String) field.get(o);
} catch (Exception e) {
throw new IllegalArgumentException(e);
@@ -72,6 +77,7 @@ public static String getValueAsString(FieldRegistration fieldRegistration, Objec
public static Boolean getValueAsBoolean(FieldRegistration fieldRegistration, Object o) {
try {
Field field = o.getClass().getDeclaredField(fieldRegistration.getName());
+ field.setAccessible(true);
return field.getBoolean(o);
} catch (Exception e) {
throw new IllegalArgumentException(e);
@@ -81,6 +87,7 @@ public static Boolean getValueAsBoolean(FieldRegistration fieldRegistration, Obj
public static Short getValueAsShort(FieldRegistration fieldRegistration, Object o) {
try {
Field field = o.getClass().getDeclaredField(fieldRegistration.getName());
+ field.setAccessible(true);
return field.getShort(o);
} catch (Exception e) {
throw new IllegalArgumentException(e);
@@ -90,6 +97,7 @@ public static Short getValueAsShort(FieldRegistration fieldRegistration, Object
public static Float getValueAsFloat(FieldRegistration fieldRegistration, Object o) {
try {
Field field = o.getClass().getDeclaredField(fieldRegistration.getName());
+ field.setAccessible(true);
return field.getFloat(o);
} catch (Exception e) {
throw new IllegalArgumentException(e);
@@ -99,6 +107,7 @@ public static Float getValueAsFloat(FieldRegistration fieldRegistration, Object
public static Byte getValueAsByte(FieldRegistration fieldRegistration, Object o) {
try {
Field field = o.getClass().getDeclaredField(fieldRegistration.getName());
+ field.setAccessible(true);
return field.getByte(o);
} catch (Exception e) {
throw new IllegalArgumentException(e);
@@ -108,6 +117,7 @@ public static Byte getValueAsByte(FieldRegistration fieldRegistration, Object o)
public static String serializeField(FieldRegistration fieldRegistration, Object tableObject) {
try {
Field field = tableObject.getClass().getDeclaredField(fieldRegistration.getName());
+ field.setAccessible(true);
Object o = field.get(tableObject);
return SerializedClassBuilder.serialize(fieldRegistration.getClass(), o);
} catch (Exception e) {

0 comments on commit e3ebddf

Please sign in to comment.