{"record":{"id":"ac8ce5c8aff7c1ae","repo":"OpenFeign/feign","slug":"empty-targets-don-t-have-urls","errorCode":null,"errorMessage":"Empty targets don't have URLs","messagePattern":"Empty targets don't have URLs","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/Target.java","lineNumber":169,"sourceCode":"    }\n\n    public static <T> EmptyTarget<T> create(Class<T> type, String name) {\n      return new EmptyTarget<T>(type, name);\n    }\n\n    @Override\n    public Class<T> type() {\n      return type;\n    }\n\n    @Override\n    public String name() {\n      return name;\n    }\n\n    @Override\n    public String url() {\n      throw new UnsupportedOperationException(\"Empty targets don't have URLs\");\n    }\n\n    @Override\n    public Request apply(RequestTemplate input) {\n      if (input.url().indexOf(\"http\") != 0) {\n        throw new UnsupportedOperationException(\n            \"Request with non-absolute URL not supported with empty target\");\n      }\n      return input.request();\n    }\n\n    @Override\n    public boolean equals(Object obj) {\n      if (obj instanceof EmptyTarget) {\n        EmptyTarget<?> other = (EmptyTarget) obj;\n        return type.equals(other.type) && name.equals(other.name);\n      }\n      return false;","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/Target.java#L151-L187","documentation":"Target.EmptyTarget represents a target without a URL (used when only the name matters, e.g. with load balancers or RequestInterceptors supplying the host). Calling url() on it is unsupported by design because no URL exists. This exception is thrown unconditionally.","triggerScenarios":"Calling Target.url() on an instance obtained via Target.EmptyTarget.create(Class) or create(Class, String); typically in code that generically inspects targets of any kind.","commonSituations":"Generic tooling/logging that iterates over Target objects assuming a concrete URL; code that swaps HardCodedTarget for EmptyTarget without updating URL accessors.","solutions":["Use Target.name() instead of url() for EmptyTarget identification","Guard with `instanceof Target.EmptyTarget` before calling url()","Provide a real Target (HardCodedTarget with URL) if your code needs a URL","Use Feign's request pipeline (apply) rather than reading the URL directly"],"exampleFix":"// before\nString url = target.url(); // throws for EmptyTarget\n// after\nString url = target instanceof Target.EmptyTarget ? null : target.url();","handlingStrategy":"type-guard","validationCode":"boolean hasUrl = !(target instanceof Target.EmptyTarget);","typeGuard":"String urlOf(Target t) { return t instanceof Target.EmptyTarget ? null : t.url(); }","tryCatchPattern":"try { url = target.url(); } catch (UnsupportedOperationException e) { url = null; }","preventionTips":["Prefer name() for EmptyTarget","Check target type before generic URL access","Document that EmptyTarget carries no URL"],"tags":["target","url","unsupported-operation","java"],"backgroundTag":"unsupported-operation","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}