@@ -114,7 +114,7 @@ private int getParentFieldInt(Object obj, String fieldName) {
114114 Field mField = getField (obj .getClass ().getSuperclass (), fieldName );
115115 mField .setAccessible (true );
116116 return mField .getInt (obj );
117- } catch (IllegalAccessException e ) {
117+ } catch (IllegalAccessException | RuntimeException e ) {
118118 e .printStackTrace ();
119119 return 0 ;
120120 }
@@ -125,7 +125,7 @@ private Object getFieldObject(Object obj, String fieldName) {
125125 Field mField = getField (obj .getClass (), fieldName );
126126 mField .setAccessible (true );
127127 return mField .get (obj );
128- } catch (IllegalAccessException e ) {
128+ } catch (IllegalAccessException | RuntimeException e ) {
129129 e .printStackTrace ();
130130 return null ;
131131 }
@@ -135,7 +135,7 @@ private Object getParentFieldObject(Object obj, String fieldName) {
135135 Field mField = getField (obj .getClass ().getSuperclass (), fieldName );
136136 mField .setAccessible (true );
137137 return mField .get (this );
138- } catch (IllegalAccessException e ) {
138+ } catch (IllegalAccessException | RuntimeException e ) {
139139 e .printStackTrace ();
140140 return null ;
141141 }
@@ -157,14 +157,15 @@ public static Field getField(Class<?> clazz, String fieldName) {
157157 }
158158
159159 public static void setParentField (Object obj , String fieldName , Object value ) {
160+ if (obj .getClass ().getSuperclass () == null ) {
161+ return ;
162+ }
160163 try {
161164 Field privateField = obj .getClass ().getSuperclass ().getDeclaredField (fieldName );
162165 privateField .setAccessible (true );
163166 privateField .set (obj , value );
164167
165- } catch (NoSuchFieldException e ) {
166- e .printStackTrace ();
167- } catch (IllegalAccessException e ) {
168+ } catch (NoSuchFieldException | IllegalAccessException e ) {
168169 e .printStackTrace ();
169170 }
170171 }
0 commit comments