{"record":{"id":"d2c5bdff1e5d2a8b","repo":"perwendel/spark","slug":"path-cannot-be-null-or-blank","errorCode":null,"errorMessage":"path cannot be null or blank","messagePattern":"path cannot be null or blank","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/spark/route/Routes.java","lineNumber":151,"sourceCode":"    public void clear() {\n        routes.clear();\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 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","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/perwendel/spark/blob/1973e402f5d4c1442ad34a1d38ed0758079f7773/src/main/java/spark/route/Routes.java#L133-L169","documentation":"Routes.remove(String path, String httpMethod) removes a previously registered route by path plus HTTP method. Spark validates the path argument with StringUtils.isEmpty and throws IllegalArgumentException when it is null or blank, because a blank path cannot identify any route.","triggerScenarios":"Calling routes.remove(null, \"GET\"), routes.remove(\"\", \"GET\"), or routes.remove(\"   \", \"GET\") on the Routes instance (e.g. via Spark's static removeRouteMapping).","commonSituations":"Path built dynamically from a config value or request parameter that is unset/empty; refactoring where the path variable was dropped; storing routes in a map where a missing key yields null.","solutions":["Pass a valid, non-blank route path (e.g. \"/api/users\") as the first argument.","Guard the call: only invoke remove when the path variable is a non-empty string.","Fix the source of the empty path (missing config property, unset field, wrong map key)."],"exampleFix":"// before\nroutes.remove(config.path(), \"GET\"); // throws if config.path() is null\n\n// after\nif (config.path() != null && !config.path().trim().isEmpty()) {\n    routes.remove(config.path(), \"GET\");\n}","handlingStrategy":"validation","validationCode":"if (path == null || path.trim().isEmpty()) throw new IllegalArgumentException(\"path must be non-blank\");\nroutes.remove(path, httpMethod);","typeGuard":null,"tryCatchPattern":"try {\n    routes.remove(path, httpMethod);\n} catch (IllegalArgumentException e) {\n    log.error(\"Invalid route removal: {}\", e.getMessage());\n}","preventionTips":["Load route paths from validated configuration, never raw user input.","Centralize route removal in a helper that checks null/blank first."],"tags":["routing","illegal-argument","null","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"}