{"record":{"id":"3d201a44eef33196","repo":"HMCL-dev/HMCL","slug":"illegal-port","errorCode":null,"errorMessage":"Illegal port: ","messagePattern":"Illegal port: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/game/ProxyOption.java","lineNumber":47,"sourceCode":"record Http(@NotNull String host, int port, @Nullable String username,\n            @Nullable String password) implements ProxyOption {\n    public Http {\n        if (StringUtils.isBlank(host)) {\n            throw new IllegalArgumentException(\"Host cannot be blank\");\n        }\n        if (port < 0 || port > 0xFFFF) {\n            throw new IllegalArgumentException(\"Illegal port: \" + port);\n        }\n    }\n}","sourceCodeStart":29,"sourceCodeEnd":64,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/game/ProxyOption.java#L29-L64","documentation":"Compact-constructor guard on the Http proxy record: the port must fit in the 16-bit unsigned range (0-65535); any out-of-range value is rejected at construction. Generic validation of a user-supplied or config-supplied port.","triggerScenarios":"Constructing Http with a negative port, a port above 65535, or an unvalidated config value like -1 used as 'unset'.","commonSituations":"Settings JSON where port was never entered and defaults to -1, users typing port numbers beyond 65535, string-to-int parsing artifacts.","solutions":["Pass a valid port in 0..65535; use 0 if 'default port' is intended","Clamp/validate the port before constructing the record","Fix the settings file so proxy.port holds a legal number","Distinguish 'no port configured' from a numeric -1 sentinel in config loading"],"exampleFix":"// before\nnew ProxyOption.Http(host, -1, null, null)\n// after\nint port = rawPort < 0 ? 0 : rawPort;\nnew ProxyOption.Http(host, port, null, null)","handlingStrategy":"validation","validationCode":"if (port < 0 || port > 0xFFFF)\n    throw new IllegalArgumentException(\"Port must be 0..65535, got \" + port);","typeGuard":"static boolean isValidPort(int port) { return port >= 0 && port <= 0xFFFF; }","tryCatchPattern":"try {\n    option = new ProxyOption.Http(host, port, null, null);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Illegal port\")) {\n        port = 0; // or re-prompt\n    } else throw e;\n}","preventionTips":["Never use -1 as an unset sentinel for ports","Range-check ports read from settings files","Constrain numeric input fields in the UI to 0-65535"],"tags":["proxy","config","port"],"backgroundTag":"value-out-of-range","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}