{"record":{"id":"7ade63677fbad7df","repo":"alibaba/nacos","slug":"illegal-url-path-expression","errorCode":null,"errorMessage":"Illegal url path expression","messagePattern":"Illegal url path expression","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/com/alibaba/nacos/client/utils/ValidatorUtils.java","lineNumber":50,"sourceCode":"    \n    private static final Pattern CONTEXT_PATH_MATCH = Pattern.compile(\"(\\\\/)\\\\1+\");\n    \n    public static void checkInitParam(NacosClientProperties properties) throws NacosException {\n        checkContextPath(properties.getProperty(PropertyKeyConst.CONTEXT_PATH));\n    }\n    \n    /**\n     * Check context path.\n     *\n     * @param contextPath context path\n     */\n    public static void checkContextPath(String contextPath) {\n        if (contextPath == null) {\n            return;\n        }\n        Matcher matcher = CONTEXT_PATH_MATCH.matcher(contextPath);\n        if (matcher.find()) {\n            throw new IllegalArgumentException(\"Illegal url path expression\");\n        }\n    }\n    \n}\n","sourceCodeStart":32,"sourceCodeEnd":55,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client/src/main/java/com/alibaba/nacos/client/utils/ValidatorUtils.java#L32-L55","documentation":"Thrown by ValidatorUtils.checkContextPath() when the configured context path contains two or more consecutive forward slashes (matched by the regex (\\/){2,}, i.e. the pattern (\\/)\\1+). A null context path is allowed (early return), but any path with '//' triggers this rejection. This is called from checkInitParam() during NacosClient/NamingService initialization.","triggerScenarios":"Setting PropertyKeyConst.CONTEXT_PATH to a value like '/nacos//' or '//nacos' or '/a//b'. The regex (\\/)\\1+ matches any run of 2+ slashes.","commonSituations":"Users prepend an extra slash when the server is behind a reverse proxy (e.g. CONTEXT_PATH='//nacos'); copy-paste from URLs where a trailing slash is doubled; misconfigured Spring property concatenation that joins two slash-terminated segments.","solutions":["Inspect the value of PropertyKeyConst.CONTEXT_PATH (property key 'contextPath') in your Nacos client Properties.","Remove duplicate consecutive slashes — a single leading slash is sufficient (e.g. '/nacos').","If building the path programmatically, normalize it with a utility that collapses runs of '/' before passing it to the client builder."],"exampleFix":"// before\nproperties.setProperty(PropertyKeyConst.CONTEXT_PATH, \"//nacos\");\n\n// after\nproperties.setProperty(PropertyKeyConst.CONTEXT_PATH, \"/nacos\");","handlingStrategy":"validation","validationCode":"String contextPath = properties.getProperty(PropertyKeyConst.CONTEXT_PATH);\nif (contextPath != null && contextPath.contains(\"//\")) {\n    throw new IllegalArgumentException(\"contextPath must not contain consecutive slashes: \" + contextPath);\n}\nValidatorUtils.checkContextPath(contextPath);","typeGuard":null,"tryCatchPattern":"try {\n    ValidatorUtils.checkInitParam(properties);\n} catch (IllegalArgumentException e) {\n    // log and provide a corrected contextPath\n    String fixed = properties.getProperty(PropertyKeyConst.CONTEXT_PATH).replaceAll(\"/+\", \"/\");\n    properties.setProperty(PropertyKeyConst.CONTEXT_PATH, fixed);\n}","preventionTips":["Sanitize context paths with replaceAll(\"/+\", \"/\") before passing to the Nacos client.","Avoid concatenating slash-terminated segments; use a join utility.","Document that the context path should have exactly one leading slash."],"tags":["configuration","validation","context-path","client-init"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}