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

  1. Add the 'pattern' entry, e.g. rule(name: 'no-tabs', pattern: '\t').
  2. Verify the pattern expression is non-null before passing it.
  3. 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

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


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/f853abd37286f06d. Report an issue: GitHub.