{"record":{"id":"6945eaba87eb3ff1","repo":"perwendel/spark","slug":"httpmethod-cannot-be-null-or-blank","errorCode":null,"errorMessage":"httpMethod cannot be null or blank","messagePattern":"httpMethod cannot be null or blank","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/spark/route/Routes.java","lineNumber":155,"sourceCode":"    /**\n     * Removes a particular route from the collection of those that have been previously routed.\n     * Search for a previously established routes using the given path and HTTP method, removing\n     * any matches that are found.\n     *\n     * @param path       the route path\n     * @param httpMethod the http method\n     * @return <tt>true</tt> if this a matching route has been previously routed\n     * @throws IllegalArgumentException if <tt>path</tt> is null or blank or if <tt>httpMethod</tt> is null, blank\n     *                                  or an invalid HTTP method\n     * @since 2.2\n     */\n    public boolean remove(String path, String httpMethod) {\n        if (StringUtils.isEmpty(path)) {\n            throw new IllegalArgumentException(\"path cannot be null or blank\");\n        }\n\n        if (StringUtils.isEmpty(httpMethod)) {\n            throw new IllegalArgumentException(\"httpMethod cannot be null or blank\");\n        }\n\n        // Catches invalid input and throws IllegalArgumentException\n        HttpMethod method = HttpMethod.valueOf(httpMethod);\n\n        return removeRoute(method, path);\n    }\n\n    /**\n     * Removes a particular route from the collection of those that have been previously routed.\n     * Search for a previously established routes using the given path and removes any matches that are found.\n     *\n     * @param path the route path\n     * @return <tt>true</tt> if this a matching route has been previously routed\n     * @throws java.lang.IllegalArgumentException if <tt>path</tt> is null or blank\n     * @since 2.2\n     */\n    public boolean remove(String path) {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/perwendel/spark/blob/1973e402f5d4c1442ad34a1d38ed0758079f7773/src/main/java/spark/route/Routes.java#L137-L173","documentation":"Routes.remove(String path, String httpMethod) validates that the HTTP method string is non-null and non-blank before converting it via HttpMethod.valueOf. An empty or null httpMethod cannot map to a route, so Spark throws IllegalArgumentException.","triggerScenarios":"Calling routes.remove(\"/path\", null), routes.remove(\"/path\", \"\"), or routes.remove(\"/path\", \"   \").","commonSituations":"HTTP method read from a variable/config/request that is unset; uppercase/lowercase mishandling leaving an empty string after trimming; a switch statement building the method name incorrectly.","solutions":["Pass a valid HTTP method string: \"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"HEAD\", \"TRACE\", \"CONNECT\", \"OPTIONS\".","Guard the call against null/blank before invoking remove.","Note the adjacent check: after this validation, HttpMethod.valueOf will also throw IllegalArgumentException for a non-blank but invalid method name, so use an exact uppercase method name."],"exampleFix":"// before\nroutes.remove(\"/users\", method); // method may be null/blank\n\n// after\nif (method != null && !method.trim().isEmpty()) {\n    routes.remove(\"/users\", method.toUpperCase());\n}","handlingStrategy":"validation","validationCode":"if (httpMethod == null || httpMethod.trim().isEmpty()) throw new IllegalArgumentException(\"httpMethod must be non-blank\");\nroutes.remove(path, httpMethod.toUpperCase());","typeGuard":null,"tryCatchPattern":"try {\n    routes.remove(path, httpMethod);\n} catch (IllegalArgumentException e) {\n    log.error(\"Invalid httpMethod for route removal: {}\", e.getMessage());\n}","preventionTips":["Use HttpMethod enum names (uppercase) instead of arbitrary strings.","Derive the method string from HttpMethod.valueOf-able constants."],"tags":["routing","http-method","illegal-argument","spark"],"backgroundTag":"empty-required-field","analyzedSha":"1973e402f5d4c1442ad34a1d38ed0758079f7773","analyzedAt":"2026-09-10T14:38:22.866Z","contentChangedAt":"2026-09-10T14:38:22.866Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}