{"record":{"id":"d3c4d18b1a99ebc5","repo":"quarkusio/quarkus","slug":"invalid-port","errorCode":null,"errorMessage":"invalid port","messagePattern":"invalid port","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java","lineNumber":350,"sourceCode":"        return this;\n\n    }\n\n    public UriBuilder userInfo(String ui) {\n        this.userInfo = ui;\n        return this;\n    }\n\n    public UriBuilder host(String host) throws IllegalArgumentException {\n        if (host != null && host.equals(\"\"))\n            throw new IllegalArgumentException(\"invalid host\");\n        this.host = host;\n        return this;\n    }\n\n    public UriBuilder port(int port) throws IllegalArgumentException {\n        if (port < -1)\n            throw new IllegalArgumentException(\"invalid port\");\n        this.port = port;\n        return this;\n    }\n\n    public UriBuilder encode(boolean encode) {\n        this.encode = encode;\n        return this;\n    }\n\n    protected static String paths(boolean encode, String basePath, String... segments) {\n        String path = basePath;\n        if (path == null)\n            path = \"\";\n        for (String segment : segments) {\n            if (\"\".equals(segment))\n                continue;\n            if (path.endsWith(\"/\")) {\n                if (segment.startsWith(\"/\")) {","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java#L332-L368","documentation":"UriBuilderImpl.port(int) throws 'invalid port' when the port is less than -1. By convention -1 means unset/default port and 0..65535 are valid; anything below -1 is rejected per the JAX-RS contract. Ports above 65535 are NOT rejected here - they fail later at request or normalization time.","triggerScenarios":"Calling builder.port(-2) or lower, usually from a parsed config value that was negative, offset arithmetic underflowing (basePort + offset), or an unvalidated negative sentinel like -999.","commonSituations":"Corrupted or placeholder-substituted config yielding a negative number; service discovery returning a negative port; derived-port arithmetic underflow.","solutions":["Validate the port before calling: accept only -1 or 0..65535, else use a default or fail","Use -1 explicitly as the only 'unset' sentinel","Range-check parsed values before use and catch IllegalArgumentException around .port(...) to log the raw value","Clamp derived values: Math.max(-1, basePort + offset)"],"exampleFix":"// before: int port = basePort + offset; builder.port(port); // throws if negative // after: int port = Math.max(-1, basePort + offset); if (port > 65535) throw new IllegalArgumentException('port out of range: ' + port); builder.port(port);","handlingStrategy":"validation","validationCode":"static int requireValidPort(int port) {\n    if (port < -1 || port > 65535)\n        throw new IllegalArgumentException('port must be -1 (unset) or 0..65535, got: ' + port);\n    return port;\n}","typeGuard":"static boolean isValidPort(int port) {\n    return port >= -1 && port <= 65535;\n}","tryCatchPattern":"try {\n    builder.port(port);\n} catch (IllegalArgumentException e) {\n    throw new IllegalArgumentException('configured port is invalid (must be >= -1): ' + port, e);\n}","preventionTips":["Use -1 as the only unset sentinel; never other negative values","Range-check parsed config values 0..65535 before use","Watch for underflow in derived-port arithmetic (basePort + offset)"],"tags":["resteasy-reactive","jaxrs","uri","port","illegal-argument"],"backgroundTag":"invalid-port-number","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}