{"record":{"id":"9e41a860ceaa1177","repo":"alibaba/Sentinel","slug":"invalid-http-status-code-httpstatus-9e41a8","errorCode":null,"errorMessage":"Invalid HTTP status code: ${httpStatus}","messagePattern":"Invalid HTTP status code: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sentinel-adapter/sentinel-web-servlet/src/main/java/com/alibaba/csp/sentinel/adapter/servlet/config/WebServletConfig.java","lineNumber":88,"sourceCode":"                throw new IllegalArgumentException(\"Invalid status code: \" + s);\n            }\n            return s;\n        } catch (Exception e) {\n            RecordLog.warn(\"[WebServletConfig] Invalid block HTTP status (\" + value + \"), using default 429\");\n            setBlockPageHttpStatus(HTTP_STATUS_TOO_MANY_REQUESTS);\n        }\n        return HTTP_STATUS_TOO_MANY_REQUESTS;\n    }\n\n    /**\n     * Set the HTTP status of the default block page.\n     *\n     * @param httpStatus the HTTP status of the default block page\n     * @since 1.7.0\n     */\n    public static void setBlockPageHttpStatus(int httpStatus) {\n        if (httpStatus <= 0) {\n            throw new IllegalArgumentException(\"Invalid HTTP status code: \" + httpStatus);\n        }\n        SentinelConfig.setConfig(BLOCK_PAGE_HTTP_STATUS_CONF_KEY, String.valueOf(httpStatus));\n    }\n\n    private WebServletConfig() {}\n}\n","sourceCodeStart":70,"sourceCodeEnd":95,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-adapter/sentinel-web-servlet/src/main/java/com/alibaba/csp/sentinel/adapter/servlet/config/WebServletConfig.java#L70-L95","documentation":"WebServletConfig.setBlockPageHttpStatus(int) (classic javax.servlet web adapter) validates the HTTP status code for Sentinel's default block page and throws IllegalArgumentException for values <= 0. The value is persisted as a string in SentinelConfig under the block-page-status key. This is a startup/configuration-time guard against nonsensical status codes.","triggerScenarios":"Calling WebServletConfig.setBlockPageHttpStatus(0) or a negative int, e.g. from a -Dcsp.sentinel.web.block.page.status=0 system property or a web.xml/context param read at startup.","commonSituations":"System property or properties file with a missing/typo'd value parsed as 0; programmatic config in a ServletContextListener running before properties are loaded; defaulting a parse failure to 0.","solutions":["Set a valid status such as 429: WebServletConfig.setBlockPageHttpStatus(429) or -Dcsp.sentinel.web.block.page.status=429","Validate parsed values: only call the setter when code > 0","Check the raw property string for typos/emptiness before Integer.parseInt"],"exampleFix":"// before\nint code = Integer.parseInt(cfg.get(\"blockPageStatus\")); // may be 0\nWebServletConfig.setBlockPageHttpStatus(code);\n\n// after\nint code = Integer.parseInt(cfg.getOrDefault(\"blockPageStatus\", \"429\"));\nWebServletConfig.setBlockPageHttpStatus(code);","handlingStrategy":"validation","validationCode":"if (code > 0) {\n    WebServletConfig.setBlockPageHttpStatus(code);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use -Dcsp.sentinel.web.block.page.status=429 style configuration with explicit valid values","Validate externally sourced ints before programmatic config calls"],"tags":["servlet","configuration","http-status","illegal-argument","web"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}