code: public static boolean parseBoolean(String valueName, String value, boolean defaultValue) {
          boolean result = defaultValue;
          if (value != null) {
              boolean valid = true;
              result = Boolean.parseBoolean(value);
              // parseBoolean allows any value, e.g. so a typo like "trye" would be silently interpreted as false
              if (!result) {
                  if (!Boolean.FALSE.toString().equalsIgnoreCase(value)) {
                      valid = false;
                  }
              }
              if (!valid) {
                  String message = String.format("Invalid value \"%s\" for %s, must be \"%s\" or \"%s\"",
                          value, valueName, Boolean.TRUE.toString(), Boolean.FALSE.toString());
                  throw new IllegalArgumentException(message);
              }
          }
          return result;
      }
docs: Validate that the given string value is a valid boolean ("true" or "false", case insensitive) and convert it to a boolean
  @param valueName
  @param value
  @param defaultValue result to be returned if value is null
  @return
  @throws IllegalArgumentException if the value is not a positive integer (including if it is an empty string)