OpenFeign/feign · error · UnsupportedOperationException

Request with non-absolute URL not supported with empty…

Error message

Request with non-absolute URL not supported with empty target

What it means

EmptyTarget.apply() cannot resolve a request whose URL is relative, because with no target base URL there is nothing to resolve it against. Only template URLs that are already absolute (start with 'http') can be turned into a Request.

Solutions

  1. Ensure a RequestInterceptor or load balancer rewrites the template to an absolute http(s) URL before the request is built
  2. Use HardCodedTarget with a base URL if no resolver exists
  3. Check that the load-balancer dependency and Targeter configuration are active
  4. Verify the interface method paths don't accidentally omit the scheme when using EmptyTarget

Example fix

// before
MyApi api = Feign.builder().target(Target.EmptyTarget.create(MyApi.class)); // path "/foo" -> exception
// after
MyApi api = Feign.builder().requestInterceptor(t -> t.header("Host", "svc")).target(Target.EmptyTarget.create(MyApi.class)); // or use HardCodedTarget("svc", "http://host")
Defensive patterns

Strategy: validation

Validate before calling

String url = template.url();
if (usingEmptyTarget && !url.startsWith("http")) throw new IllegalStateException("path must be absolute with EmptyTarget: " + url);

Type guard

boolean isAbsolute(String u) { return u != null && (u.startsWith("http://") || u.startsWith("https://")); }

Try / catch

try { req = emptyTarget.apply(template); } catch (UnsupportedOperationException e) { throw new IllegalStateException("Configure a host interceptor/load balancer for EmptyTarget", e); }

Prevention

When it happens

Trigger: Building a Feign client with Target.EmptyTarget.create(Interface.class) and invoking a method whose path is relative (e.g. "/api/users") without any interceptor or load-balancer rewriting the template to an absolute URL.

Common situations: Using EmptyTarget with client-side load balancing (Ribbon/feign-lb) but forgetting the RequestInterceptor that injects the host; misconfigured load-balancer target resolution; calling apply() manually in custom code.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10). Data as JSON: /api/errors/42b7934e11c09e0b. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/feign/Target.java:175

    @Override
    public Class<T> type() {
      return type;
    }

    @Override
    public String name() {
      return name;
    }

    @Override
    public String url() {
      throw new UnsupportedOperationException("Empty targets don't have URLs");
    }

    @Override
    public Request apply(RequestTemplate input) {
      if (input.url().indexOf("http") != 0) {
        throw new UnsupportedOperationException(
            "Request with non-absolute URL not supported with empty target");
      }
      return input.request();
    }

    @Override
    public boolean equals(Object obj) {
      if (obj instanceof EmptyTarget) {
        EmptyTarget<?> other = (EmptyTarget) obj;
        return type.equals(other.type) && name.equals(other.name);
      }
      return false;
    }

    @Override
    public int hashCode() {
      int result = 17;
      result = 31 * result + type.hashCode();

View on GitHub (pinned to e2a1e27560)