elastic/elasticsearch · error · InvalidUserDataException

Missing [name] for invalid pattern rule

Error message

Missing [name] for invalid pattern rule

What it means

Thrown by ForbiddenPatternsTask.rule(Map) when the supplied map has no 'name' key. Each forbidden-pattern rule must be named (the name keys the rule in the patterns map and is reported on violations), so a missing name is rejected as invalid user data at configuration time.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ForbiddenPatternsTask.java:188

    @OutputFile
    public File getOutputMarker() {
        return new File(projectLayout.getBuildDirectory().getAsFile().get(), "markers/" + getName());
    }

    @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();

View on GitHub (pinned to db6a809a66)

Solutions

  1. Add a 'name' entry to the rule map, e.g. rule(name: 'no-tabs', pattern: '\t').
  2. Check for typos in the key (case-sensitive 'name').
  3. Re-run the task to confirm configuration succeeds.

Example fix

// before
rule pattern: '\\t'

// after
rule name: 'no-tabs', pattern: '\\t'
Defensive patterns

Strategy: validation

Validate before calling

// In rule(), validate keys up front
if (!props.containsKey("name")) throw new InvalidUserDataException("Missing [name] for invalid pattern rule");

Prevention

When it happens

Trigger: Calling rule([pattern: '...']) or rule([:]) — any rule(Map) invocation whose map lacks the 'name' entry.

Common situations: A build script rule block with a typo ('Name' instead of 'name'); a copied rule missing the name line; an auto-generated rule config that omitted the name.

Related errors


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