elastic/elasticsearch · error · InvalidUserDataException
Missing [pattern] for invalid pattern rule
Error message
Missing [pattern] for invalid pattern rule
What it means
Thrown by ForbiddenPatternsTask.rule(Map) when the 'name' key is present but the 'pattern' key is missing. A rule needs a regex pattern to be useful; without one the task rejects the rule as invalid user data.
Source
Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ForbiddenPatternsTask.java:192
}
@Input
public Map<String, String> getPatterns() {
return Collections.unmodifiableMap(patterns);
}
public void exclude(String... excludes) {
filesFilter.exclude(excludes);
}
public void rule(Map<String, String> props) {
String name = props.remove("name");
if (name == null) {
throw new InvalidUserDataException("Missing [name] for invalid pattern rule");
}
String pattern = props.remove("pattern");
if (pattern == null) {
throw new InvalidUserDataException("Missing [pattern] for invalid pattern rule");
}
if (props.isEmpty() == false) {
throw new InvalidUserDataException("Unknown arguments for ForbiddenPatterns rule mapping: " + props.keySet().toString());
}
// TODO: fail if pattern contains a newline, it won't work (currently)
patterns.put(name, pattern);
}
@Internal
abstract ListProperty<FileTree> getSourceFolders();
@Internal
abstract Property<File> getRootDir();
@Input
@Optional
Provider<String> getRootDirPath() {
return getRootDir().map(t -> t.toPath().relativize(projectLayout.getProjectDirectory().getAsFile().toPath()).toString());View on GitHub (pinned to db6a809a66)
Solutions
- Add the 'pattern' entry, e.g. rule(name: 'no-tabs', pattern: '\t').
- Verify the pattern expression is non-null before passing it.
- Re-run to confirm.
Example fix
// before rule name: 'no-tabs' // after rule name: 'no-tabs', pattern: '\\t'
Defensive patterns
Strategy: validation
Validate before calling
if (!props.containsKey("pattern")) throw new InvalidUserDataException("Missing [pattern] for invalid pattern rule"); Prevention
- Always supply pattern as a non-null literal or verified variable.
- Use named-argument DSL style so the pair is visually checked.
- Unit-test the regex separately before wiring it in.
When it happens
Trigger: Calling rule([name: 'foo']) — map has 'name' but no 'pattern'.
Common situations: A rule block that names the rule but forgets the pattern line; refactor that moved the pattern into a variable that resolved to null.
Related errors
- Missing [name] for invalid pattern rule
- Unknown arguments for ForbiddenPatterns rule mapping: {}
- No signatures were added to task; use properties 'signatures
- Missing 'classesDirs' or 'classpath' property.
- No dependencies variable defined.
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/f853abd37286f06d.
Report an issue: GitHub.