{"record":{"id":"2b218dd17c4d4375","repo":"apache/shardingsphere","slug":"invalid-port-s","errorCode":null,"errorMessage":"Invalid port `%s`.","messagePattern":"Invalid port `(.+?)`\\.","errorType":"console","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"critical","filePath":"proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/arguments/BootstrapArguments.java","lineNumber":60,"sourceCode":"    \n    /**\n     * Get port.\n     *\n     * @return port\n     * @throws IllegalArgumentException illegal argument exception\n     */\n    public Optional<Integer> getPort() {\n        if (0 == args.length) {\n            return Optional.empty();\n        }\n        try {\n            int port = Integer.parseInt(args[0]);\n            if (port < 0) {\n                return Optional.empty();\n            }\n            return Optional.of(port);\n        } catch (final NumberFormatException ignored) {\n            throw new IllegalArgumentException(String.format(\"Invalid port `%s`.\", args[0]));\n        }\n    }\n    \n    /**\n     * Get configuration path.\n     *\n     * @return configuration path\n     */\n    public String getConfigurationPath() {\n        return args.length < 2 ? DEFAULT_CONFIG_PATH : paddingWithSlash(args[1]);\n    }\n    \n    private String paddingWithSlash(final String pathArg) {\n        StringBuilder result = new StringBuilder(pathArg);\n        if (!pathArg.startsWith(\"/\")) {\n            result.insert(0, '/');\n        }\n        if (!pathArg.endsWith(\"/\")) {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/arguments/BootstrapArguments.java#L42-L78","documentation":"IllegalArgumentException ('Invalid port `%s`.') thrown by BootstrapArguments.getPort when the first command-line argument to ShardingSphere-Proxy is present but Integer.parseInt(args[0]) fails. Note the asymmetric behavior: a negative number does NOT throw — it returns Optional.empty() so the configured default port is used — while any non-numeric first argument aborts startup with this exception.","triggerScenarios":"Starting the proxy as `java -jar shardingsphere-proxy-bootstrap.jar foo` (or `3307a`, `0x3307`, ` 3307` with whitespace) where args[0] cannot be parsed as an int; NumberFormatException is caught and rethrown as IllegalArgumentException.","commonSituations":"Passing flags in the wrong order (e.g. putting the config path first); shell quoting/whitespace issues injecting stray characters; copy-pasting a start command with a placeholder like <port> still in it.","solutions":["Pass the port as the first argument as a plain decimal integer: `java -jar shardingsphere-proxy-bootstrap.jar 3307 conf/server.yaml`","If you want the port from server.yaml, omit the argument entirely rather than passing a placeholder","Sanitize shell scripts that build the command line (check for stray spaces or template placeholders)"],"exampleFix":"# before\njava -jar shardingsphere-proxy-bootstrap.jar conf/server.yaml\n\n# after\njava -jar shardingsphere-proxy-bootstrap.jar 3307 conf/server.yaml","handlingStrategy":"validation","validationCode":"// start-script guard: validate argv before exec\nString portArg = args.length > 0 ? args[0] : null;\nif (portArg != null && !portArg.matches(\"\\\\d+\")) {\n    System.err.println(\"First argument must be a numeric port or be omitted\");\n    System.exit(2);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep argument order fixed: port, config path, addresses; never shuffle or insert flags","Generate startup commands from templates with resolved placeholders; fail CI on unresolved '<port>' tokens"],"tags":["bootstrap","cli","arguments","startup","port"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}