{"record":{"id":"c1807affb0f596d7","repo":"apache/shenyu","slug":"gateway-address-uri-is-not-invalid","errorCode":null,"errorMessage":"Gateway address uri is not invalid.","messagePattern":"Gateway address uri is not invalid\\.","errorType":"exception","errorClass":"ShenyuException","httpStatus":null,"severity":"error","filePath":"shenyu-sdk/shenyu-sdk-feign/src/main/java/org/apache/shenyu/sdk/feign/ShenyuDiscoveryClient.java","lineNumber":102,"sourceCode":"                throw new ShenyuException(\"Gateway address not found from registry.\");\n            }\n            upstreams = instanceRegisters.stream().map(instanceRegister -> {\n                final String instanceUrl = String.join(Constants.COLONS, instanceRegister.getHost(), Integer.toString(instanceRegister.getPort()));\n                return Upstream.builder().url(UriUtils.appendScheme(instanceUrl, scheme)).build();\n            }).collect(Collectors.toList());\n        }\n        // loadBalancer upstreams\n        if (CollectionUtils.isEmpty(upstreams)) {\n            LOG.error(\"The serviceId that named {} could not load balanced to at least one upstream.\", serviceId);\n        }\n        Upstream upstream = upstreams.get(0);\n        if (CollectionUtils.isNotEmpty(upstreams) && upstreams.size() > 1) {\n            upstream = LoadBalancerFactory.selector(upstreams, algorithm, new LoadBalanceData());\n        }\n\n        final URI uri = UriUtils.createUri(upstream.getUrl());\n        if (Objects.isNull(uri)) {\n            throw new ShenyuException(\"Gateway address uri is not invalid.\");\n        }\n        return new DefaultServiceInstance(upstream.getUrl(), serviceId, uri.getHost(), uri.getPort(), HttpSchemeEnum.HTTPS.getScheme().equals(scheme));\n    }\n\n}\n","sourceCodeStart":84,"sourceCodeEnd":108,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-sdk/shenyu-sdk-feign/src/main/java/org/apache/shenyu/sdk/feign/ShenyuDiscoveryClient.java#L84-L108","documentation":"After selecting an upstream (load-balanced or single), getInstance() converts the upstream URL into a java.net.URI via UriUtils.createUri(). If that returns null the URL was unparseable, so the SDK throws ShenyuException rather than returning a ServiceInstance with null host/port.","triggerScenarios":"An upstream URL from serverLists or the registry that UriUtils.createUri cannot parse — e.g. missing scheme after appendScheme fails, empty string, or characters illegal in a URI.","commonSituations":"serverLists entries without a valid scheme and a bad scheme configuration; registry storing malformed host values; whitespace or commas left in the configured address list; configuring an IPv6 literal without brackets.","solutions":["Fix the offending upstream address in serverLists or in the registry so it parses as host:port, e.g. http://localhost:9195.","Ensure the configured scheme is valid (http/https) so UriUtils.appendScheme produces a well-formed URL.","Trim whitespace and stray commas from the comma-separated server list.","Log/inspect upstream.getUrl() just before the call to identify which entry is malformed."],"exampleFix":"// before\nserverLists: \" http://localhost:9195, \"\n// after\nserverLists: \"http://localhost:9195\"","handlingStrategy":"validation","validationCode":"for (String addr : serverLists.split(\",\")) {\n    String trimmed = addr.trim();\n    if (!trimmed.isEmpty() && UriUtils.createUri(UriUtils.appendScheme(trimmed, \"http\")) == null) {\n        throw new IllegalArgumentException(\"Unparseable gateway address: \" + trimmed);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim and validate every entry in comma-separated server lists.","Store addresses as scheme://host:port consistently in config and registry.","Bracket IPv6 literals and avoid raw special characters in host values."],"tags":["uri-parsing","discovery","configuration"],"backgroundTag":"invalid-url","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}