apache/shenyu · critical · ShenyuException

sync.consul.url formatter is not incorrect.

Error message

sync.consul.url formatter is not incorrect.

What it means

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.

Solutions

  1. Include a valid scheme, e.g. http://consul:8500 or https://consul.example.com:8500.
  2. Trim the configured value of whitespace/quotes and re-check YAML indentation.
  3. Test the string with new URL(value) locally to confirm it parses.
  4. Use the Consul agent's standard HTTP API port (8500) with a reachable host.

Example fix

# before
consul:
  url: localhost:8500
# after
consul:
  url: http://localhost:8500
Defensive patterns

Strategy: validation

Validate before calling

try { new java.net.URL(url); } catch (MalformedURLException e) { throw new IllegalStateException("sync.consul.url must be a full URL like http://host:8500"); }

Type guard

boolean isValidUrl(String s) { try { new java.net.URL(s); return true; } catch (MalformedURLException e) { return false; } }

Try / catch

try { return new ConsulSyncConfiguration().consulClient(props); } catch (ShenyuException e) { log.error("Bad consul URL '{}': {}", props.getUrl(), e.getMessage()); throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/4710c717bbd17cdc. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-admin-listener/shenyu-admin-listener-consul/src/main/java/org/apache/shenyu/admin/config/ConsulSyncConfiguration.java:61

public class ConsulSyncConfiguration {

    /**
     * init Consul client.
     *
     * @param consulProperties the consul properties
     * @return Consul client
     */
    @Bean
    public ConsulClient consulClient(final ConsulProperties consulProperties) {
        String url = consulProperties.getUrl();
        if (StringUtils.isBlank(url)) {
            throw new ShenyuException("sync.consul.url can not be null.");
        }
        try {
            URL consulUrl = new URL(url);
            return consulUrl.getPort() < 0 ? new ConsulClient(consulUrl.getHost()) : new ConsulClient(consulUrl.getHost(), consulUrl.getPort());
        } catch (MalformedURLException e) {
            throw new ShenyuException("sync.consul.url formatter is not incorrect.");
        }
    }

    /**
     * Config event listener data changed listener.
     *
     * @param consulClient the consul client
     * @return the data changed listener
     */
    @Bean
    @ConditionalOnMissingBean(ConsulDataChangedListener.class)
    public DataChangedListener consulDataChangedListener(final ConsulClient consulClient) {
        return new ConsulDataChangedListener(consulClient);
    }

    /**
     * Consul data init.
     *

View on GitHub (pinned to 567142e072)