quarkusio/quarkus · error · IllegalArgumentException
Invalid template ${template}
Error message
Invalid template ${template} What it means
URITemplate's constructor parses URI templates into path components. This IllegalArgumentException is thrown when a '{' segment containing a custom regex is malformed — e.g. a template like "{id:regex(...)}" whose inner expression does not match the expected custom-regex syntax, so the parser reaches an invalid state inside state 1.
Source
Thrown at independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/mapping/URITemplate.java:78
litChars++;
sb.append(c);
}
break;
case 1:
if (c == '}') {
state = 0;
if (sb.length() > 0) {
capGroups++;
if (i + 1 == template.length() || template.charAt(i + 1) == '/') {
components
.add(new TemplateComponent(Type.DEFAULT_REGEX, null, sb.toString().trim(), null, null,
null));
} else {
components.add(new TemplateComponent(Type.CUSTOM_REGEX, "[^/]+?", sb.toString().trim(),
null, null, null));
}
} else {
throw new IllegalArgumentException("Invalid template " + template);
}
sb.setLength(0);
} else if (c == ':') {
name = sb.toString().trim();
sb.setLength(0);
state = 2;
} else {
sb.append(c);
}
break;
case 2:
if (c == '}' && bracesCount == 0) {
state = 0;
if (sb.length() > 0) {
capGroups++;
complexGroups++;
components
.add(new TemplateComponent(Type.CUSTOM_REGEX, sb.toString().trim(), name, null,View on GitHub (pinned to e1c734241f)
Solutions
- Fix the template syntax inside braces; for custom regex use the form {name:regex("pattern")} or {name:pattern} supported by the parser
- Escape or remove characters inside the braces that break parsing (unmatched parens/brackets)
- Simplify to a plain parameter {name} if no custom pattern is needed
- Test the template string in a unit test constructing new URITemplate(...) to fail fast
Example fix
// before
@Path("/items/{id:regex(")
// after
@Path("/items/{id:regex("\\d+")}") Defensive patterns
Strategy: validation
Validate before calling
// validate template before use
if (template.matches(".*\\{[^}]*:regex\\([^)]*$")) {
throw new IllegalArgumentException("Malformed custom regex in template: " + template);
} Try / catch
try {
new URITemplate(template);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Fix @Path on resource class: " + e.getMessage(), e);
} Prevention
- Use the documented custom regex form {name:regex("pattern")}
- Test every custom @Path template in a unit test at build time
- Avoid copy-pasting template syntax from other frameworks
- Escape regex special characters inside patterns
When it happens
Trigger: Declaring a path parameter with an invalid custom regex form in a URI template, e.g. @Path("/items/{id:regex(") or an unrecognized special keyword after ':' inside braces that the parser cannot map to a TemplateComponent.
Common situations: Typos in custom regex declarations; copying templates from other frameworks (Spring/Spray syntax) unsupported here; unbalanced or unescaped regex characters inside braces; using unsupported syntax like {id: int} misspelled.
Related errors
- Invalid template ${template} Unmatched { braces
- Path not specified
- Name cannot start with '/':${name}
- Predicate already set
- Location already set
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/a4ec0678cfccad72.
Report an issue: GitHub.