code: public static long parsePositiveInteger(String valueName, String value, long defaultValue) {
          long result = defaultValue;
          if (value != null) {
              boolean valid = true;
              try {
                  result = Long.parseLong(value);
                  if (result <= 0) {
                      valid = false;
                  }
              }
              catch (NumberFormatException e) {
                  valid = false;
              }
              if (!valid) {
                  String message = String.format("Invalid value \"%s\" for %s, must be a positive integer",
                          value, valueName);
                  throw new IllegalArgumentException(message);
              }
          }
          return result;
      }
docs: Validate that the given string value is a valid positive integer (int or long) and convert it to a long
  @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)