elastic/elasticsearch · error · InvalidUserDataException

Unknown arguments for ForbiddenPatterns rule mapping

Error message

Unknown arguments for ForbiddenPatterns rule mapping: {}

What it means

Thrown by ForbiddenPatternsTask.rule(Map) after 'name' and 'pattern' have been removed: if the map is not empty there are leftover keys, meaning the caller passed unsupported arguments. The rule DSL accepts exactly 'name' and 'pattern'; anything else is a typo or a misuse.

Solutions

  1. Inspect the reported key set in the message and remove the unsupported entries.
  2. Keep only 'name' and 'pattern' in the rule map.
  3. Re-run to confirm.

Example fix

// before
rule name: 'no-tabs', pattern: '\\t', severity: 'error'

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

Strategy: validation

Validate before calling

Set<String> allowed = Set.of("name", "pattern");
Set<String> extra = new HashSet<>(props.keySet()); extra.removeAll(allowed);
if (!extra.isEmpty()) throw new InvalidUserDataException("Unknown keys: " + extra);

Prevention

When it happens

Trigger: Calling rule with extra keys, e.g. rule(name: 'x', pattern: 'y', description: 'z') or a misspelled key like 'patterns'.

Common situations: Typos (e.g. 'Patterns' instead of 'pattern'); copying a richer rule DSL from another plugin; stale keys left after a refactor.

Understand the failure class

Related errors


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

Appendix: source

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

    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)