{"record":{"id":"4ba5fce96914cd36","repo":"quarkusio/quarkus","slug":"invalid-template-template-unmatched-braces","errorCode":null,"errorMessage":"Invalid template ${template} Unmatched { braces","messagePattern":"Invalid template (.+?) Unmatched \\{ braces","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/mapping/URITemplate.java","lineNumber":125,"sourceCode":"                            bracesCount--;\n                        }\n                    }\n                    break;\n            }\n        }\n        switch (state) {\n            case 0:\n                if (sb.length() > 0) {\n                    String literal = sb.toString();\n                    stem = handlePossibleStem(components, stem, literal);\n                }\n                break;\n            case 1:\n            case 2:\n                throw new IllegalArgumentException(\"Invalid template \" + template);\n        }\n        if (bracesCount > 0) {\n            throw new IllegalArgumentException(\"Invalid template \" + template + \" Unmatched { braces\");\n        }\n\n        //coalesce the components\n        //once we have a CUSTOM_REGEX everything goes out the window, so we need to turn the remainder of the\n        //template into a single CUSTOM_REGEX\n        List<String> groupAggregator = null;\n        List<String> nameAggregator = null;\n        StringBuilder regexAggregator = null;\n        Iterator<TemplateComponent> it = components.iterator();\n        while (it.hasNext()) {\n            TemplateComponent component = it.next();\n\n            if (component.type == Type.CUSTOM_REGEX && nameAggregator == null) {\n                regexAggregator = new StringBuilder();\n                groupAggregator = new ArrayList<>();\n                nameAggregator = new ArrayList<>();\n            }\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/mapping/URITemplate.java#L107-L143","documentation":"After successfully scanning the URI template, URITemplate checks bracesCount > 0: an unmatched '{' remains, so the constructor throws IllegalArgumentException(\"Invalid template \" + template + \" Unmatched { braces\"). This happens when a literal '{' appears without a matching '}' or is nested incorrectly.","triggerScenarios":"Templates containing '{' that never closes, or nested braces like \"/a/{x/{y}}\" or a stray '{' in a literal segment — bracesCount incremented on '{' but never decremented to zero.","commonSituations":"Regex patterns inside parameters that themselves contain '{' (quantifiers like {2,3}) without the parser's expected nesting; accidental double braces from format strings; concatenating partial templates each missing braces.","solutions":["Balance all braces: every '{' in the template must have a matching '}'","For regex quantifiers inside custom patterns, verify the parser supports the nested-brace form or rewrite the pattern (e.g. [0-9]{2,3} inside {id:regex(...)}) and confirm nesting is counted correctly","Escape or remove stray literal '{' from the path"],"exampleFix":"// before\n@Path(\"/items/{id\") // or \"/items/{id:{2}\" with unbalanced braces\n\n// after\n@Path(\"/items/{id:regex(\"[0-9]{2,3}\")}\")","handlingStrategy":"validation","validationCode":"// every '{' must be closed before template use\nint depth = 0;\nfor (char c : template.toCharArray()) {\n    if (c == '{') depth++;\n    if (c == '}') depth--;\n    if (depth < 0) throw new IllegalArgumentException(\"Unmatched } in: \" + template);\n}\nif (depth != 0) throw new IllegalArgumentException(\"Unmatched { in: \" + template);","typeGuard":null,"tryCatchPattern":"try {\n    new URITemplate(template);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Unmatched { braces\")) {\n        throw new IllegalStateException(\"Fix unbalanced '{' in path template: \" + template, e);\n    }\n    throw e;\n}","preventionTips":["Keep regex quantifiers like {2,3} only inside properly closed parameter expressions","Run a startup test that constructs all resource templates","Avoid string-format placeholders (%s, {}) colliding with template braces"],"tags":["routing","uri-template","illegal-argument","unbalanced-braces"],"backgroundTag":"invalid-uri-template","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"}