code: private static Object getFieldVal(final Class<?> cls, final Object obj, final String fieldName,
              final boolean throwException) throws IllegalArgumentException {
          Field field = null;
          for (Class<?> currClass = cls; currClass != null; currClass = currClass.getSuperclass()) {
              try {
                  field = currClass.getDeclaredField(fieldName);
                  // Field found
                  break;
              } catch (final ReflectiveOperationException | SecurityException e) {
                  // Try parent
              }
          }
          if (field == null) {
              if (throwException) {
                  throw new IllegalArgumentException((obj == null ? "Static field " : "Field ") + "\"" + fieldName
                          + "\" not found or not accessible");
              }
          } else {
              try {
                  field.setAccessible(true);
              } catch (final RuntimeException e) { // JDK 9+: InaccessibleObjectException | SecurityException
                  // Ignore
              }
              try {
                  return field.get(obj);
              } catch (final IllegalAccessException e) {
                  if (throwException) {
                      throw new IllegalArgumentException(
                              "Can't read " + (obj == null ? "static " : "") + " field \"" + fieldName + "\": " + e);
                  }
              }
          }
          return null;
      }
docs: Get the value of the named field in the class of the given object or any of its superclasses. If an exception
  is thrown while trying to read the field, and throwException is true, then IllegalArgumentException is thrown
  wrapping the cause, otherwise this will return null. If passed a null object, returns null unless
  throwException is true, then throws IllegalArgumentException.
  
  @param cls
  The class.
  @param obj
  The object, or null to get the value of a static field.
  @param fieldName
  The field name.
  @param throwException
  If true, throw an exception if the field value could not be read.
  @return The field value.
  @throws IllegalArgumentException
  If the field value could not be read.