{"record":{"id":"80047aeaa31947d7","repo":"alibaba/nacos","slug":"404-80047a","errorCode":"404","errorMessage":"Invalid URI","messagePattern":"Invalid URI","errorType":"http","errorClass":"NacosRuntimeException","httpStatus":404,"severity":"warning","filePath":"core/src/main/java/com/alibaba/nacos/core/code/ControllerMethodsCache.java","lineNumber":220,"sourceCode":"    }\n    \n    private String stripContextPath(String path, String contextPath) {\n        if (StringUtils.isEmpty(path) || StringUtils.isEmpty(contextPath)) {\n            return path;\n        }\n        if (path.startsWith(contextPath)) {\n            String stripped = path.substring(contextPath.length());\n            return StringUtils.isEmpty(stripped) ? StringUtils.EMPTY : stripped;\n        }\n        return path;\n    }\n    \n    private String getPath(HttpServletRequest request) {\n        try {\n            return new URI(request.getRequestURI()).getPath();\n        } catch (URISyntaxException e) {\n            LOGGER.error(\"parse request to path error\", e);\n            throw new NacosRuntimeException(NacosException.NOT_FOUND, \"Invalid URI\");\n        }\n    }\n    \n    private List<RequestMappingInfo> findMatchedInfo(List<RequestMappingInfo> requestMappingInfos,\n        HttpServletRequest request) {\n        List<RequestMappingInfo> matchedInfo = new ArrayList<>();\n        for (RequestMappingInfo requestMappingInfo : requestMappingInfos) {\n            ParamRequestCondition matchingCondition = requestMappingInfo.getParamRequestCondition()\n                .getMatchingCondition(request);\n            if (matchingCondition != null) {\n                matchedInfo.add(requestMappingInfo);\n            }\n        }\n        return matchedInfo;\n    }\n    \n    /**\n     * find target method from this package.","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/core/src/main/java/com/alibaba/nacos/core/code/ControllerMethodsCache.java#L202-L238","documentation":"Thrown when request.getRequestURI() cannot be parsed by new URI(...).getPath() because the raw request URI violates RFC 2396 syntax (URISyntaxException). Returned as a 404 NacosRuntimeException (NacosException.NOT_FOUND) from the legacy resolver's getPath helper.","triggerScenarios":"A client sends a request line whose URI contains characters/structure that java.net.URI rejects — unencoded spaces, mismatched brackets, illegal escape sequences, or a malformed proxy-generated URI reaching the legacy resolver.","commonSituations":"Reverse proxy misconfiguration that forwards an unescaped/mangled request URI; a hand-crafted HTTP request with an invalid target; URL-encoding bugs in a client SDK that leave reserved characters unencoded.","solutions":["URL-encode the request path correctly on the client side (spaces -> %20, etc.).","Fix the reverse proxy (nginx/ingress) to pass a well-formed, percent-encoded request URI.","If the legacy resolver is not required, run without it (default) so this getPath() path is not exercised."],"exampleFix":"// before\nGET /v3/admin/ns/instance?serviceName=a b HTTP/1.1\n\n// after (encode the value)\nGET /v3/admin/ns/instance?serviceName=a%20b HTTP/1.1","handlingStrategy":"validation","validationCode":"String raw = request.getRequestURI();\ntry { new URI(raw).getPath(); }\ncatch (URISyntaxException e) { /* reject 400 at the proxy/gateway before it reaches Nacos */ }","typeGuard":null,"tryCatchPattern":"try {\n    controllerMethodsCache.getMethod(request);\n} catch (NacosRuntimeException e) {\n    if (e.getErrCode() == NacosException.NOT_FOUND) { /* invalid URI from client */ }\n}","preventionTips":["URL-encode request paths on the client.","Configure the reverse proxy to forward well-formed, percent-encoded URIs."],"tags":["spring-mvc","uri","http","legacy-resolver","not-found"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}