{"record":{"id":"ff8a1476c0e1c820","repo":"OpenFeign/feign","slug":"target-is-not-a-valid-uri","errorCode":null,"errorMessage":"Target is not a valid URI.","messagePattern":"Target is not a valid URI\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/RequestTemplate.java","lineNumber":532,"sourceCode":"      /* parse the target */\n      URI targetUri = URI.create(target);\n\n      if (Util.isNotBlank(targetUri.getRawQuery())) {\n        /*\n         * target has a query string, we need to make sure that they are recorded as queries\n         */\n        this.extractQueryTemplates(targetUri.getRawQuery(), true);\n      }\n\n      /* strip the query string */\n      this.target =\n          targetUri.getScheme() + \"://\" + targetUri.getRawAuthority() + targetUri.getRawPath();\n      if (targetUri.getFragment() != null) {\n        this.fragment = \"#\" + targetUri.getFragment();\n      }\n    } catch (IllegalArgumentException iae) {\n      /* the uri provided is not a valid one, we can't continue */\n      throw new IllegalArgumentException(\"Target is not a valid URI.\", iae);\n    }\n    return this;\n  }\n\n  /**\n   * The URL for the request. If the template has not been resolved, the url will represent a uri\n   * template.\n   *\n   * @return the url\n   */\n  public String url() {\n\n    /* build the fully qualified url with all query parameters */\n    StringBuilder url = new StringBuilder(this.path());\n    if (!this.queries.isEmpty()) {\n      url.append(this.queryLine());\n    }\n    if (fragment != null) {","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/RequestTemplate.java#L514-L550","documentation":"RequestTemplate.target(String) parses the target into a URI. If parsing fails (malformed URI, illegal characters, bad port, etc.), the caught IllegalArgumentException is rethrown as 'Target is not a valid URI.' with the original cause attached.","triggerScenarios":"Passing a syntactically invalid target such as 'https://exa mple.com', 'http://host:notaport/', or a URL with unescaped illegal characters to target(); thrown during insert/create/apply flows.","commonSituations":"Unencoded spaces or non-ASCII characters in configured base URLs, corrupted env/config values, ports or IPv6 literals formatted incorrectly.","solutions":["Percent-encode illegal characters or remove them from the target URL","Validate the base URL with new URI(url) or UriUtils before configuring Feign","Check the cause (iae.getCause()) in logs for the exact parse failure (bad port, illegal char)","Fix the environment/config value supplying the target"],"exampleFix":"// before\ntemplate.target(\"https://api.example.com/a b\");\n// after\ntemplate.target(\"https://api.example.com/a%20b\");","handlingStrategy":"try-catch","validationCode":"try {\n  new java.net.URI(baseUrl); // throws if invalid\n} catch (java.net.URISyntaxException e) {\n  throw new IllegalArgumentException(\"Invalid configured base URL: \" + baseUrl, e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  template.target(baseUrl);\n} catch (IllegalArgumentException e) {\n  if (\"Target is not a valid URI.\".equals(e.getMessage())) {\n    LOGGER.error(\"Malformed target '{}', cause: {}\", baseUrl, e.getCause());\n    throw new ConfigurationException(\"Fix base URL encoding: \" + baseUrl, e);\n  }\n  throw e;\n}","preventionTips":["Percent-encode spaces and non-ASCII characters in URLs","Validate base URLs with new URI(...) before configuring Feign","Log e.getCause() to identify the exact URI parse problem","Avoid hand-built URLs from concatenation; use URI builders"],"tags":["java","feign-client","url","configuration"],"backgroundTag":"invalid-url-format","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"}