public static List<InstanceField> allDeclaredFieldsOf(Object testInstance) {
    List<InstanceField> result = new ArrayList<>();
    for (Class<?> clazz = testInstance.getClass();
         clazz != Object.class;
         clazz = clazz.getSuperclass()) {
      for (Field field : clazz.getDeclaredFields()) {
        result.add(new InstanceField(field, testInstance));
      }
    }
    return result;
  }
Sets a declared field in a given object. It finds the field, even if it is declared in a super class.
@param object target instance
@param field name of the field to set
@param value new value
@throws RuntimeException in case the field is not found or cannot be set.
common/src/java/org/apache/hive/common/util/ReflectionUtil.java