{"record":{"id":"2e4859c0a72edf4d","repo":"quarkusio/quarkus","slug":"failed-to-create-uri","errorCode":null,"errorMessage":"Failed to create URI","messagePattern":"Failed to create URI","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java","lineNumber":528,"sourceCode":"        if (values == null)\n            throw new IllegalArgumentException(\"Values parameter is null\");\n        return buildUriFromMap(values, true, false);\n    }\n\n    public URI buildFromMap(Map<String, ?> values, boolean encodeSlashInPath)\n            throws IllegalArgumentException, UriBuilderException {\n        if (values == null)\n            throw new IllegalArgumentException(\"Values parameter is null\");\n        return buildUriFromMap(values, false, encodeSlashInPath);\n    }\n\n    protected URI buildUriFromMap(Map<String, ? extends Object> paramMap, boolean fromEncodedMap, boolean encodeSlash)\n            throws IllegalArgumentException, UriBuilderException {\n        String buf = buildString(paramMap, fromEncodedMap, false, encodeSlash);\n        try {\n            return URI.create(buf);\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to create URI\", e);\n        }\n    }\n\n    private String buildString(Map<String, ? extends Object> paramMap, boolean fromEncodedMap, boolean isTemplate,\n            boolean encodeSlash) {\n        return buildCharSequence(paramMap, fromEncodedMap, isTemplate, encodeSlash).toString();\n    }\n\n    private CharSequence buildCharSequence(Map<String, ? extends Object> paramMap, boolean fromEncodedMap, boolean isTemplate,\n            boolean encodeSlash) {\n        StringBuilder builder = new StringBuilder();\n\n        if (scheme != null)\n            replaceParameter(paramMap, fromEncodedMap, isTemplate, scheme, builder, encodeSlash).append(\":\");\n        if (ssp != null) {\n            builder.append(ssp);\n        } else if (userInfo != null || host != null || port != -1) {\n            builder.append(\"//\");","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java#L510-L546","documentation":"UriBuilderImpl wraps any exception from URI.create(buf) when turning the fully-substituted template string into a java.net.URI. It means the interpolated URI string is syntactically invalid per RFC 2396 (illegal characters, bad scheme/authority form), not that a template value was missing. The underlying parse exception is chained as the cause.","triggerScenarios":"Calling UriBuilder.build(Map)/buildFromMap/buildFromEncodedMap where a supplied parameter value introduces characters illegal in a URI (unencoded spaces, '{', '|', non-ASCII) or produces a malformed authority/scheme, so URI.create() on the built string throws.","commonSituations":"User path/query values taken from user input or config containing spaces or unicode; forgetting that build() (not buildFromEncoded()) encodes values; building URIs from concatenated string templates with raw data; property values with trailing junk copied from docs.","solutions":["Inspect the chained cause (e.getCause()) to see the exact illegal character or position reported by URI.create","Pre-encode parameter values with URLEncoder.encode(v, UTF_8) or pass them through UriBuilder.resolveTemplate/queryParam which encode automatically","Remove or fix the offending characters in the template or map values (e.g. replace spaces with %20)","Validate the final string with URI.create() in dev to catch this early"],"exampleFix":"// before\nURI uri = UriBuilder.fromUri(\"https://api.example.com/{q}\").build(\"raw value with space\");\n// after\nURI uri = UriBuilder.fromUri(\"https://api.example.com\").queryParam(\"q\", \"{q}\").build(\"raw value with space\");","handlingStrategy":"validation","validationCode":"String s = builder.clone().build(params).toString(); // or pre-check in dev\n// validate values before build:\nfor (Map.Entry<String, ?> e : paramMap.entrySet()) {\n    Object v = e.getValue();\n    if (v != null && (v.toString().contains(\" \") || v.toString().contains(\"{\"))) {\n        throw new IllegalArgumentException(\"Value for \" + e.getKey() + \" contains characters needing URI encoding\");\n    }\n}","typeGuard":"static boolean isUriSafe(String s) {\n    return s != null && java.net.URI.create(s).toString().equals(s) == false || s.chars().allMatch(c -> c > 32 && c < 127 && c != '{' && c != '}' && c != '|');\n}","tryCatchPattern":"try {\n    URI uri = builder.build(params);\n} catch (RuntimeException e) {\n    if (e.getCause() != null) throw new IllegalStateException(\"Invalid URI string: \" + e.getCause().getMessage(), e);\n    throw e;\n}","preventionTips":["Always pass raw values through UriBuilder's own encoding (queryParam/path/resolveTemplate), never pre-concatenate strings","Log the built string (buildString result) when a build fails to spot illegal characters quickly","Add tests that build every client URI with realistic user-supplied values"],"tags":["uri","resteasy-reactive","encoding"],"backgroundTag":"invalid-uri-syntax","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}