Skip to content

Commit

Permalink
getDeclaredField raises exception instead of returning null when fiel…
Browse files Browse the repository at this point in the history
…d isn't found

(cherry picked from commit 348d873)
  • Loading branch information
tint0 committed Jan 30, 2019
1 parent 6ba90d2 commit 04c198a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/ysoserial/payloads/util/Reflections.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
@SuppressWarnings ( "restriction" )
public class Reflections {

public static Field getField(final Class<?> clazz, final String fieldName) throws Exception {
Field field = clazz.getDeclaredField(fieldName);
if (field != null)
field.setAccessible(true);
else if (clazz.getSuperclass() != null)
field = getField(clazz.getSuperclass(), fieldName);
public static Field getField(final Class<?> clazz, final String fieldName) {
Field field = null;
try {
field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
}
catch (NoSuchFieldException ex) {
if (clazz.getSuperclass() != null)
field = getField(clazz.getSuperclass(), fieldName);
}
return field;
}

Expand Down

0 comments on commit 04c198a

Please sign in to comment.