{"record":{"id":"4710c717bbd17cdc","repo":"apache/shenyu","slug":"sync-consul-url-formatter-is-not-incorrect","errorCode":null,"errorMessage":"sync.consul.url formatter is not incorrect.","messagePattern":"sync\\.consul\\.url formatter is not incorrect\\.","errorType":"exception","errorClass":"ShenyuException","httpStatus":null,"severity":"critical","filePath":"shenyu-admin-listener/shenyu-admin-listener-consul/src/main/java/org/apache/shenyu/admin/config/ConsulSyncConfiguration.java","lineNumber":61,"sourceCode":"public class ConsulSyncConfiguration {\n\n    /**\n     * init Consul client.\n     *\n     * @param consulProperties the consul properties\n     * @return Consul client\n     */\n    @Bean\n    public ConsulClient consulClient(final ConsulProperties consulProperties) {\n        String url = consulProperties.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    /**\n     * Config event listener data changed listener.\n     *\n     * @param consulClient the consul client\n     * @return the data changed listener\n     */\n    @Bean\n    @ConditionalOnMissingBean(ConsulDataChangedListener.class)\n    public DataChangedListener consulDataChangedListener(final ConsulClient consulClient) {\n        return new ConsulDataChangedListener(consulClient);\n    }\n\n    /**\n     * Consul data init.\n     *","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin-listener/shenyu-admin-listener-consul/src/main/java/org/apache/shenyu/admin/config/ConsulSyncConfiguration.java#L43-L79","documentation":"consulClient parses sync.consul.url with java.net.URL. If the string is not a well-formed URL (missing scheme, illegal characters, wrong syntax), MalformedURLException is caught and rethrown as ShenyuException with this message.","triggerScenarios":"Setting sync.consul.url to something new URL(...) cannot parse — e.g. \"localhost:8500\" without scheme, \"http:/wrong\", or a value with stray spaces/quotes.","commonSituations":"Forgetting the http:// scheme, YAML quoting issues that leave whitespace in the value, or using a host:port shorthand that java.net.URL does not accept without a scheme.","solutions":["Include a valid scheme, e.g. http://consul:8500 or https://consul.example.com:8500.","Trim the configured value of whitespace/quotes and re-check YAML indentation.","Test the string with new URL(value) locally to confirm it parses.","Use the Consul agent's standard HTTP API port (8500) with a reachable host."],"exampleFix":"# before\nconsul:\n  url: localhost:8500\n# after\nconsul:\n  url: http://localhost:8500","handlingStrategy":"validation","validationCode":"try { new java.net.URL(url); } catch (MalformedURLException e) { throw new IllegalStateException(\"sync.consul.url must be a full URL like http://host:8500\"); }","typeGuard":"boolean isValidUrl(String s) { try { new java.net.URL(s); return true; } catch (MalformedURLException e) { return false; } }","tryCatchPattern":"try { return new ConsulSyncConfiguration().consulClient(props); } catch (ShenyuException e) { log.error(\"Bad consul URL '{}': {}\", props.getUrl(), e.getMessage()); throw e; }","preventionTips":["Always include the scheme (http:// or https://) in sync.consul.url.","Validate URL syntax in configuration tests at build/deploy time.","Watch for YAML folding/quoting that injects stray whitespace.","Use the standard Consul HTTP port 8500 in the URL."],"tags":["consul","url","config-sync"],"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"}