apache/shenyu · error · IllegalArgumentException

is malformed

Error message

 is malformed

What it means

Identical validation to the feign SDK: the spring SDK's ShenyuClientsRegistrar.getUrl() resolves the @ShenyuClient url attribute, strips a trailing slash, and validates it with java.net.URL. A string the URL constructor cannot parse causes IllegalArgumentException("<url> is malformed") with the MalformedURLException as cause, failing at bean registration time.

Solutions

  1. Prefix the address with its scheme: url = "http://localhost:9195".
  2. Define the referenced property so the placeholder resolves before registration.
  3. Trim whitespace from the configured value.
  4. Verify with a quick check in a test: new java.net.URL(resolvedUrl) should not throw.

Example fix

// before
@ShenyuClient(name = "order", url = "localhost:9195")
// after
@ShenyuClient(name = "order", url = "http://localhost:9195")
Defensive patterns

Strategy: validation

Validate before calling

String url = env.resolvePlaceholders(clientUrl).trim();
try { new java.net.URL(url); }
catch (MalformedURLException e) {
    throw new IllegalArgumentException("@ShenyuClient url invalid: " + url, e);
}

Prevention

When it happens

Trigger: A spring-module @ShenyuClient whose url attribute resolves (after placeholder substitution) to something not parseable by java.net.URL — missing scheme, unresolved ${placeholder}, illegal characters, or empty string.

Common situations: Forgetting http:// in the annotation or yml; property key typo so ${shenyu.gateway} stays literal; leading/trailing spaces from YAML values; using a registry-style bare address where a full URL is required.

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/d3898e88091f1ce3. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/ShenyuClientsRegistrar.java:370

    /**
     * Gets url.
     *
     * @param url the url
     * @return the url
     */
    static String getUrl(final String url) {
        String resultUrl = url;
        if (StringUtils.isNotBlank(resultUrl) && !(resultUrl.startsWith("#{") && resultUrl.contains("}"))) {
            if (!resultUrl.contains("://")) {
                resultUrl = "http://" + resultUrl;
            }
            if (resultUrl.endsWith("/")) {
                resultUrl = resultUrl.substring(0, resultUrl.length() - 1);
            }
            try {
                new URL(resultUrl);
            } catch (MalformedURLException e) {
                throw new IllegalArgumentException(resultUrl + " is malformed", e);
            }
        }
        return resultUrl;
    }

    private String getUrl(final ConfigurableBeanFactory beanFactory, final Map<String, Object> attributes) {
        String url = resolve(beanFactory, (String) attributes.get("url"));
        if (StringUtils.isBlank(url)) {
            return getUrl(getName(beanFactory, attributes));
        }
        return getUrl(url);
    }

    private String getPath(final ConfigurableBeanFactory beanFactory, final Map<String, Object> attributes) {
        String path = resolve(beanFactory, (String) attributes.get("path"));
        return getPath(path);
    }

View on GitHub (pinned to 567142e072)