{"record":{"id":"9b5fed4f8659bf48","repo":"apache/shenyu","slug":"sync-consul-url-formatter-is-not-incorrect-9b5fed","errorCode":null,"errorMessage":"sync.consul.url formatter is not incorrect.","messagePattern":"sync\\.consul\\.url formatter is not incorrect\\.","errorType":"validation","errorClass":"ShenyuException","httpStatus":null,"severity":"error","filePath":"shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-consul/src/main/java/org/apache/shenyu/springboot/sync/data/consul/ConsulSyncDataConfiguration.java","lineNumber":111,"sourceCode":"    }\n\n\n    /**\n     * init Consul client.\n     * @param consulConfig the consul config\n     * @return Consul client\n     */\n    @Bean\n    public ConsulClient consulClient(final ConsulConfig consulConfig) {\n        String url = consulConfig.getUrl();\n        if (StringUtils.isBlank(url)) {\n            throw new ShenyuException(\"sync.consul.url can not be null.\");\n        }\n        try {\n            URL consulUrl = new URL(url);\n            return consulUrl.getPort() < 0 ? new ConsulClient(consulUrl.getHost()) : new ConsulClient(consulUrl.getHost(), consulUrl.getPort());\n        } catch (MalformedURLException e) {\n            throw new ShenyuException(\"sync.consul.url formatter is not incorrect.\");\n        }\n    }\n}\n","sourceCodeStart":93,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-consul/src/main/java/org/apache/shenyu/springboot/sync/data/consul/ConsulSyncDataConfiguration.java#L93-L115","documentation":"This error is thrown when ShenYu initializes the Consul config-sync client at startup and the configured `shenyu.sync.consul.url` property cannot be parsed by `java.net.URL` as a valid absolute URL. The starter wraps the resulting `MalformedURLException` in a `ShenyuException`, which fails the Spring bean creation of `ConsulClient` and therefore aborts gateway bootstrapping. The message wording is awkward (it means the URL format is incorrect, not a formatter issue), but the cause is always a malformed `sync.consul.url` value.","triggerScenarios":"Spring bean `consulClient` in ConsulSyncDataConfiguration calls `new URL(url)` where `url` comes from `shenyu.sync.consul.url` in application.yml/properties; if the value is not a parseable absolute URL (e.g. missing scheme like `localhost:8500`, illegal characters, spaces, or a bad port like `http://consul:port`), `MalformedURLException` is thrown and rethrown as this ShenyuException.","commonSituations":"Developers set `shenyu.sync.consul.url: localhost:8500` forgetting the `http://` scheme (the most common case, since a plain host:port is not a valid URL), paste URLs with trailing spaces or quotes, use an invalid port number, or point at a scheme like `https` with typo characters. It typically surfaces immediately on gateway startup with a bean-creation stack trace.","solutions":["Add a valid scheme to `shenyu.sync.consul.url`, e.g. `http://localhost:8500` instead of `localhost:8500`","Verify the property value has no stray spaces, quotes, or invisible characters (check the exact value in your application.yml/properties or environment variable)","Ensure the port is numeric and in range (1-65535); remove placeholders like `${CONSUL_URL}` left unresolved","Cross-check against the ShenYu docs example config for the consul sync starter and restart after fixing"],"exampleFix":"# before (application.yml) — missing scheme, not a parseable URL\nshenyu:\n  sync:\n    consul:\n      url: localhost:8500\n# after\nshenyu:\n  sync:\n    consul:\n      url: http://localhost:8500","handlingStrategy":"validation","validationCode":"public static void validateConsulUrl(String url) {\n    if (url == null || url.isBlank()) {\n        throw new IllegalArgumentException(\"shenyu.sync.consul.url is required\");\n    }\n    try {\n        java.net.URL u = new java.net.URI(url).toURL();\n        if (u.getHost() == null) {\n            throw new IllegalArgumentException(\"shenyu.sync.consul.url must include a host, e.g. http://localhost:8500\");\n        }\n    } catch (Exception e) {\n        throw new IllegalArgumentException(\"shenyu.sync.consul.url is not a valid URL: \" + url, e);\n    }\n}","typeGuard":"public static boolean isValidUrl(String url) {\n    if (url == null || url.isBlank()) {\n        return false;\n    }\n    try {\n        return new java.net.URI(url).toURL().getHost() != null;\n    } catch (Exception e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    ConsulClient client = buildConsulClient(config.getUrl());\n} catch (ShenyuException e) {\n    if (e.getMessage().contains(\"sync.consul.url formatter\")) {\n        log.error(\"Invalid shenyu.sync.consul.url '{}': must be an absolute URL like http://host:8500\", config.getUrl(), e);\n    }\n    throw e; // fail fast: the gateway cannot sync config without Consul\n}","preventionTips":["Always include the scheme (http:// or https://) in shenyu.sync.consul.url — host:port alone is not a valid URL","Validate the URL in CI or at config load time before deploying the gateway","Use a startup smoke test that constructs the URL with java.net.URL/URI before wiring the bean","Avoid unexpanded placeholders and stray whitespace in environment-injected config values"],"tags":["config","consul","url-format","startup"],"backgroundTag":"invalid-url-format","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"}