code: public static int parsePort(String port, Integer defaultPort) {
      try {
        return Integer.parseInt(trim(port));
      }
      catch (NumberFormatException cause) {
        return Optional.ofNullable(defaultPort)
          .orElseThrow(() -> newIllegalArgumentException(cause, "Port [%s] is not valid", port));
      }
    }
docs: Parses the given {@link String} as a numeric port number.
  
  @param port {@link String} to parse as a numeric port number.
  @param defaultPort {@link Integer} value used as the default port number
  if the {@link String} port number is not valid.
  @return a numeric port number from the given {@link String}.
  @throws IllegalArgumentException if the {@link String} port number is not valid
  and {@code defaultPort} is {@literal null}.
  @see java.lang.Integer#parseInt(String)