{"record":{"id":"d87e0082e0c77280","repo":"quarkusio/quarkus","slug":"invalid-status-code","errorCode":null,"errorMessage":"Invalid status code: ","messagePattern":"Invalid status code: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/CloseReason.java","lineNumber":30,"sourceCode":" * @see WebSocketClientConnection#close(CloseReason)\n */\npublic class CloseReason {\n\n    public static final CloseReason NORMAL = new CloseReason(WebSocketCloseStatus.NORMAL_CLOSURE.code());\n\n    public static final CloseReason ABNORMAL = new CloseReason(WebSocketCloseStatus.ABNORMAL_CLOSURE.code(), null, false);\n\n    public static final CloseReason EMPTY = new CloseReason(WebSocketCloseStatus.EMPTY.code(), null, false);\n\n    public static final CloseReason INTERNAL_SERVER_ERROR = new CloseReason(WebSocketCloseStatus.INTERNAL_SERVER_ERROR.code());\n\n    private final int code;\n\n    private final String message;\n\n    private CloseReason(int code, String message, boolean validate) {\n        if (validate && !WebSocketCloseStatus.isValidStatusCode(code)) {\n            throw new IllegalArgumentException(\"Invalid status code: \" + code);\n        }\n        this.code = code;\n        this.message = message;\n    }\n\n    /**\n     *\n     * @param code The status code must comply with RFC-6455\n     */\n    public CloseReason(int code) {\n        this(code, null, true);\n    }\n\n    /**\n     *\n     * @param code The status code must comply with RFC-6455\n     * @param message\n     */","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/CloseReason.java#L12-L48","documentation":"CloseReason validates WebSocket close status codes. RFC 6455/Quarkus restrict which codes may be used when closing (1000, 1001, 3000-4999, etc.); codes like 1004-1006 or out-of-range values are invalid. Passing such a code to the validating CloseReason constructor throws IllegalArgumentException 'Invalid status code: <code>'.","triggerScenarios":"Calling CloseReason(int) or CloseReason(int, String) with a code rejected by WebSocketCloseStatus.isValidStatusCode — e.g. 0, 999, 1004, 1015, or > 4999.","commonSituations":"Hard-coding a status code read from a spec of another framework; using reserved codes (1004, 1005, 1006, 1015) which must not be sent on the wire; a config property feeding an arbitrary int.","solutions":["Use a WebSocketCloseStatus enum constant (e.g. WebSocketCloseStatus.NORMAL_CLOSURE) instead of a raw int","Validate the code with WebSocketCloseStatus.isValidStatusCode(code) before constructing the CloseReason","Use the code range 3000-4999 for application-specific close codes"],"exampleFix":"// before\nCloseReason reason = new CloseReason(1006); // reserved, invalid\n// after\nCloseReason reason = new CloseReason(WebSocketCloseStatus.GOING_AWAY.getCode());","handlingStrategy":"validation","validationCode":"CloseReason safeCloseReason(int code) {\n    if (!WebSocketCloseStatus.isValidStatusCode(code))\n        throw new IllegalArgumentException(\"Code not sendable: \" + code);\n    return new CloseReason(code);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use WebSocketCloseStatus constants instead of raw ints","Restrict application codes to 3000-4999; never use reserved codes 1004-1006, 1015"],"tags":["websockets","validation","status-code"],"backgroundTag":"invalid-close-status-code","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"}