mirror of
https://github.com/frohoff/ysoserial.git
synced 2026-09-21 22:50:46 +08:00
getDeclaredField raises exception instead of returning null when field isn't found
(cherry picked from commit 348d873)
This commit is contained in:
@@ -9,12 +9,16 @@ import sun.reflect.ReflectionFactory;
|
|||||||
@SuppressWarnings ( "restriction" )
|
@SuppressWarnings ( "restriction" )
|
||||||
public class Reflections {
|
public class Reflections {
|
||||||
|
|
||||||
public static Field getField(final Class<?> clazz, final String fieldName) throws Exception {
|
public static Field getField(final Class<?> clazz, final String fieldName) {
|
||||||
Field field = clazz.getDeclaredField(fieldName);
|
Field field = null;
|
||||||
if (field != null)
|
try {
|
||||||
field.setAccessible(true);
|
field = clazz.getDeclaredField(fieldName);
|
||||||
else if (clazz.getSuperclass() != null)
|
field.setAccessible(true);
|
||||||
field = getField(clazz.getSuperclass(), fieldName);
|
}
|
||||||
|
catch (NoSuchFieldException ex) {
|
||||||
|
if (clazz.getSuperclass() != null)
|
||||||
|
field = getField(clazz.getSuperclass(), fieldName);
|
||||||
|
}
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user