languagetool-org/languagetool · error · IOException

Invalid port configuration found. The value for '--port' nee

Error message

Invalid port configuration found. The value for '--port' need to be greater than 0 or if set to 0 you need to specify a minPort and maxPort in your properties file (minPort must be lower that maxPort).

What it means

getPortFromRange validates port configuration: either --port must be > 0, or --port 0 must be combined with minPort and maxPort properties (minPort < maxPort). If neither valid form is found it throws this IOException. It is a configuration validation error, not a network problem.

Source

Thrown at languagetool-server/src/main/java/org/languagetool/server/HTTPServer.java:149

  
  private int getPortFromRange(int minPort, int maxPort) throws IOException {
    if (minPort > 0 && minPort < maxPort) {
         log.info("Try to find a free Port for Server in range {}-{}", minPort, maxPort);
         for (int p = minPort; p <= maxPort; p++) {
           try {
             log.info("Check port {}", p);
             ServerSocket serverSocket = new ServerSocket(p);
             port = serverSocket.getLocalPort();
             serverSocket.close();
             log.info("Port {} is available.", p);
             return p;
           } catch (IOException ex) {
             log.debug("Port {} is not available.", p);
           }
         }
         throw new IOException("No free port in range ("+ minPort + " - " + maxPort + ") found.");
    } else {
      throw new IOException("Invalid port configuration found. " +
                            "The value for '--port' need to be greater than 0 or if set to 0 you need to specify a minPort and maxPort in your properties file (minPort must be lower that maxPort).");
    }
  }

  @Override
  public void stop() {
    super.stop();
    if (executorService != null) {
      executorService.shutdownNow();
    }
  }

  public static void main(String[] args) {
    if (usageRequested(args)) {
      System.out.println("Usage: " + HTTPServer.class.getSimpleName() + " [--config propertyFile] [--port|-p port] [--public]");
      System.out.println("  --config FILE  a Java property file (one key=value entry per line) with values for:");
      printCommonConfigFileOptions();
      printCommonOptions();

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Set --port (or the port property) to a specific positive port number
  2. If dynamic ports are required, add valid minPort and maxPort (minPort < maxPort) to the server properties file
  3. Verify the property file actually passed via --config is the one being read
  4. Check for typos in property keys: exactly 'minPort' and 'maxPort'

Example fix

# before
java -cp languagetool-server.jar org.languagetool.server.HTTPServer --port 0 --config server.properties
# after (server.properties)
minPort=8081
maxPort=8090
# and keep: --port 0
Defensive patterns

Strategy: validation

Validate before calling

// validate before launch
Properties p = loadProps(configFile);
int port = Integer.parseInt(cmdPort);
if (port <= 0) {
  int min = Integer.parseInt(p.getProperty("minPort", "0"));
  int max = Integer.parseInt(p.getProperty("maxPort", "0"));
  if (min <= 0 || max <= 0 || min >= max) throw new IllegalArgumentException("Need --port > 0 or valid minPort<maxPort");
}

Try / catch

try { new HTTPServerConfig(args); } catch (IOException e) {
  if (e.getMessage().startsWith("Invalid port configuration")) { fixPropsOrUseStaticPort(); } else throw e;
}

Prevention

When it happens

Trigger: Starting the server with --port 0 (or port<=0) without defining minPort/maxPort in the properties file, or defining them such that minPort >= maxPort.

Common situations: Copy-pasting a properties file that lacks the minPort/maxPort keys while using port=0; typos in property names; setting minPort equal to or above maxPort by mistake.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/1e964d75e1992529. Report an issue: GitHub.