{"record":{"id":"d7881d8f7c9939da","repo":"quarkusio/quarkus","slug":"failed-to-create-uri-d7881d","errorCode":null,"errorMessage":"failed to create URI","messagePattern":"failed to create URI","errorType":"exception","errorClass":"UriBuilderException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java","lineNumber":753,"sourceCode":"        }\n    }\n\n    public URI build(Object... values) throws IllegalArgumentException, UriBuilderException {\n        if (values == null)\n            throw new IllegalArgumentException(\"Values parameter is null\");\n        return buildFromValues(true, false, values);\n    }\n\n    protected URI buildFromValues(boolean encodeSlash, boolean encoded, Object... values) {\n        String buf = null;\n        try {\n            buf = buildString(new URITemplateParametersMap(values), encoded, false, encodeSlash);\n            return new URI(buf);\n            //return URI.create(buf);\n        } catch (IllegalArgumentException iae) {\n            throw iae;\n        } catch (Exception e) {\n            throw new UriBuilderException(\"failed to create URI\", e);\n        }\n    }\n\n    public UriBuilder matrixParam(String name, Object... values) throws IllegalArgumentException {\n        if (name == null)\n            throw new IllegalArgumentException(\"Name parameter is null\");\n        if (values == null)\n            throw new IllegalArgumentException(\"Values parameter is null\");\n        if (path == null)\n            path = \"\";\n        for (Object val : values) {\n            if (val == null)\n                throw new IllegalArgumentException(\"Value is null\");\n            String matrixName = encode ? Encode.encodeMatrixParam(name) : name;\n            String matrixValue = encode ? Encode.encodeMatrixParam(val.toString()) : val.toString();\n            path += \";\" + matrixName + \"=\" + matrixValue;\n        }\n        return this;","sourceCodeStart":735,"sourceCodeEnd":771,"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#L735-L771","documentation":"UriBuilderException wrapping a failure from new URI(buf) in buildFromValues: the fully substituted template string could not be parsed as a URI. Unlike the IllegalArgumentException cases (missing/null params) which pass through unchanged, this fires after substitution succeeded but the resulting string is malformed (illegal characters or bad URI structure). The original exception is chained as the cause.","triggerScenarios":"build(Object...)/buildFromValues where a substituted value contains characters illegal in a URI component (space, '{', control chars, non-ASCII) and the encoding flag (encoded=true path) skipped escaping, or the template itself forms a bad URI once values are inserted.","commonSituations":"Using buildFromValues(..., encoded=true, ...) with values that are not actually pre-encoded; inserting user input into path segments without encoding; values containing '{'/'}' left over from nested templates; scheme or authority fragments glued together incorrectly.","solutions":["Read e.getCause() (URISyntaxException) for the exact index and reason of the parse failure","Encode values before building: use Encode/URLEncoder for path segments and query params, or call build() with encoding enabled (encoded=false)","If values are legitimately already encoded, strip or escape stray reserved characters ('{', '}', space) before passing them","Construct via UriBuilder path()/queryParam() methods rather than string concatenation so each component is encoded correctly"],"exampleFix":"// before\nURI u = UriBuilder.fromUri(\"/files/{name}\").buildFromValues(false, true, \"my file.txt\"); // claims pre-encoded\n// after\nURI u = UriBuilder.fromUri(\"/files/{name}\").build(URLEncoder.encode(\"my file.txt\", StandardCharsets.UTF_8));","handlingStrategy":"try-catch","validationCode":"// pre-validate values are URI-safe or already encoded\nfor (Object v : values) {\n    String s = String.valueOf(v);\n    if (s.chars().anyMatch(c -> c <= 32 || c == '{' || c == '}' || c > 127)) {\n        throw new IllegalArgumentException(\"Value needs URI encoding: \" + s);\n    }\n}","typeGuard":"static boolean isEncoded(String s) { return s != null && java.util.stream.IntStream.of(s.chars().toArray()).noneMatch(c -> c <= 32 || c == '{' || c == '}'); }","tryCatchPattern":"try {\n    URI uri = builder.build(values);\n} catch (UriBuilderException e) {\n    throw new IllegalStateException(\"Built URI string invalid: \" + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()), e);\n}","preventionTips":["Only pass encoded=true/buildFromEncoded when values are guaranteed pre-encoded","Always read the chained cause — URISyntaxException pinpoints the bad character and index","Build URIs via path()/queryParam() methods so components are encoded individually"],"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-14T00:17:10.932Z"}