private static Field findField(Object instance,String name) throws NoSuchFieldException {
  for (Class<?> clazz=instance.getClass(); clazz != null; clazz=clazz.getSuperclass()) {
    try {
      Field field=clazz.getDeclaredField(name);
      if (!field.isAccessible()) {
        field.setAccessible(true);
      }
      return field;
    }
 catch (    NoSuchFieldException e) {
    }
  }
  throw new NoSuchFieldException("Field " + name + " not found in "+ instance.getClass());
}

private static Field findField ( Object instance , String name ) throws NoSuchFieldException { for ( Class < ? > clazz = instance . getClass ( ) ; clazz != null ; clazz = clazz . getSuperclass ( ) ) { try { Field field = clazz . getDeclaredField ( name ) ; if ( ! field . isAccessible ( ) ) { field . setAccessible ( true ) ; } return field ; } catch ( NoSuchFieldException e ) { } } throw new NoSuchFieldException ( "Field " + name + " not found in " + instance . getClass ( ) ) ; }
locates a given field anywhere in the class inheritance hierarchy .
