public static void setInAllFields(Object object, String field, Object value) {
    try {
      Field fieldToChange = Arrays.stream(FieldUtils.getAllFields(object.getClass()))
              .filter(f -> f.getName().equals(field))
              .findFirst()
              .orElseThrow(NoSuchFieldException::new);

      fieldToChange.setAccessible(true);

      fieldToChange.set(object, value);
    } catch (NoSuchFieldException | IllegalAccessException e) {
      throw new RuntimeException("Cannot set field %s in object %s".formatted(field, object.getClass()));
    }
  }
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