{"record":{"id":"1b85bdd2bd31dbee","repo":"OpenFeign/feign","slug":"invalid-uri-request-url","errorCode":null,"errorMessage":"Invalid uri ${request.url()}","messagePattern":"Invalid uri (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"java11/src/main/java/feign/http2client/Http2Client.java","lineNumber":100,"sourceCode":"            .connectTimeout(Duration.ofMillis(10000))\n            .build());\n  }\n\n  public Http2Client(Options options) {\n    this(newClientBuilder(options).version(Version.HTTP_2).build());\n  }\n\n  public Http2Client(HttpClient client) {\n    this.client = Util.checkNotNull(client, \"HttpClient must not be null\");\n  }\n\n  @Override\n  public Response execute(Request request, Options options) throws IOException {\n    final HttpRequest httpRequest;\n    try {\n      httpRequest = newRequestBuilder(request, options).version(client.version()).build();\n    } catch (URISyntaxException e) {\n      throw new IOException(\"Invalid uri \" + request.url(), e);\n    }\n\n    HttpClient clientForRequest = getOrCreateClient(options);\n    HttpResponse<InputStream> httpResponse;\n    try {\n      httpResponse = clientForRequest.send(httpRequest, BodyHandlers.ofInputStream());\n    } catch (final InterruptedException e) {\n      Thread.currentThread().interrupt();\n      throw new IOException(e);\n    }\n\n    return toFeignResponse(request, httpResponse);\n  }\n\n  @Override\n  public CompletableFuture<Response> execute(\n      Request request, Options options, Optional<Object> requestContext) {\n    HttpRequest httpRequest;","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/java11/src/main/java/feign/http2client/Http2Client.java#L82-L118","documentation":"The synchronous java11 Http2Client builds a java.net.http.HttpRequest from the Feign Request's URL. If that URL cannot be parsed as a valid URI (URISyntaxException), it is rethrown as an IOException with the message 'Invalid uri <url>'. Feign templates can produce invalid URLs when unencoded special characters or spaces leak into the path or query.","triggerScenarios":"execute() on Http2Client when Request.url() contains characters illegal in a URI - spaces, unencoded '|', '{', '}', non-ASCII characters, or a malformed host/scheme produced by a bad @RequestLine or unexpanded template values.","commonSituations":"Path/query parameters containing spaces or unicode without Encoding; building URLs manually with Target.EmptyTarget and bad base URLs; Feign version upgrades changing default encoding behavior; template placeholders left unsubstituted.","solutions":["Log request.url() from the wrapped IOException to see the offending URL","Encode path/query values: use Util.encode or URLEncoder for user-supplied parameters","Fix the @RequestLine / base URL (scheme://host syntax, no spaces)","Percent-encode the target URL before building the client, or use a RequestInterceptor to sanitize URLs","Verify no template placeholder ({param}) remains unexpanded"],"exampleFix":"// before\n@RequestLine(\"GET /search?q={q}\") Response search(@Param(\"q\") String q);\napi.search(\"hello world|foo\");\n// after\napi.search(URLEncoder.encode(\"hello world|foo\", StandardCharsets.UTF_8));\n// or fix the request line: @RequestLine(\"GET /search?q={q}\") with properly encoded params","handlingStrategy":"validation","validationCode":"String url = request.url();\ntry {\n  new java.net.URI(url); // throws URISyntaxException if invalid\n} catch (URISyntaxException e) {\n  throw new IllegalStateException(\"Request URL is not a valid URI: \" + url, e);\n}","typeGuard":"static boolean isValidUri(String s) {\n  try { new java.net.URI(s); return true; } catch (URISyntaxException e) { return false; }\n}","tryCatchPattern":"try {\n  return client.execute(request, options);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid uri\")) {\n    throw new IllegalArgumentException(\"Fix request URL encoding: \" + e.getMessage(), e);\n  }\n  throw e;\n}","preventionTips":["Percent-encode all user-supplied path and query values (URLEncoder / Util.encode)","Validate the Target base URL has scheme://host and no stray whitespace","Never leave {placeholder} tokens unexpanded in @RequestLine templates","Add a RequestInterceptor that asserts new URI(url) parses before sending","Test interfaces with inputs containing spaces, '|', unicode, and CJK characters"],"tags":["java11","httpclient","url","feign"],"backgroundTag":"invalid-url","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"}