code: void checkPort(int port, String msg) {
          StringBuilder message = new StringBuilder().append(" ").append(msg);
          String portInUseError = String.format("Port %d is already in use. Please shutdown the service "
                  + "listening on this port or configure a different port%s.", port, message);
          boolean free = false;
          try {
              free = PortProber.pollPort(port);
          } catch (RuntimeException e) {
              throw new IllegalArgumentException(portInUseError, e);
          } finally {
              if (!free) {
                  throw new IllegalArgumentException(portInUseError);
              }
          }
      }
docs: Check the port availability
  
  @param port
  the port to check
  @param msg
  the text to append to the end of the error message displayed when the port is not available.
  @throws IllegalArgumentException
  when the port is not available.