elastic/elasticsearch · error · IllegalStateException

variantPrefixes, variantBaseClasses, and variantSpecFilePatt

Error message

variantPrefixes, variantBaseClasses, and variantSpecFilePatterns must have the same length

What it means

Thrown by GenerateEsqlSpecTestsTask.generate() when the three parallel List properties — variantPrefixes, variantBaseClasses, and variantSpecSpecFilePatterns — have different sizes. These lists are zipped together to generate variant spec test classes, so they must have equal length. The check is performed after all three are materialized from their Provider wrappers.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/esql/GenerateEsqlSpecTestsTask.java:100

    public abstract FileSystemOperations getFileSystemOperations();

    @TaskAction
    public void generate() throws IOException {
        File outputDir = getOutputDirectory().getAsFile().get();
        getFileSystemOperations().delete(spec -> spec.delete(outputDir));

        String packageName = getPackageName().get();
        String packagePath = packageName.replace('.', '/');
        File packageDir = new File(outputDir, packagePath);
        if (packageDir.mkdirs() == false && packageDir.exists() == false) {
            throw new IOException("Could not create directory: " + packageDir);
        }

        List<String> prefixes = getVariantPrefixes().get();
        List<String> baseClasses = getVariantBaseClasses().get();
        List<String> allEncodedPatterns = getVariantSpecFilePatterns().get();
        if (prefixes.size() != baseClasses.size() || prefixes.size() != allEncodedPatterns.size()) {
            throw new IllegalStateException("variantPrefixes, variantBaseClasses, and variantSpecFilePatterns must have the same length");
        }

        File specDir = getSpecFilesDir().getAsFile().get();
        File[] specFiles = specDir.listFiles((dir, name) -> name.endsWith(".csv-spec"));
        if (specFiles == null) {
            return;
        }
        Arrays.sort(specFiles);
        for (File specFile : specFiles) {
            String specFileName = specFile.getName();
            String baseName = specFileName.substring(0, specFileName.length() - ".csv-spec".length());
            String pascalName = toPascalCase(baseName);
            for (int i = 0; i < prefixes.size(); i++) {
                String encoded = allEncodedPatterns.get(i);
                List<String> patterns = encoded.isEmpty() ? List.of() : Arrays.asList(encoded.split(","));
                if (patterns.isEmpty() == false && matchesAnyPattern(specFile, patterns) == false) {
                    continue;
                }

View on GitHub (pinned to db6a809a66)

Solutions

  1. Inspect the task configuration in build.gradle and ensure all three lists have the same number of entries.
  2. If lists are generated programmatically, add an assertion in the configuration block: assert prefixes.size() == baseClasses.size() && prefixes.size() == patterns.size().
  3. Log the three list sizes before the task runs to diagnose which list is short: println variantPrefixes.get().size().

Example fix

// before
generateEsqlSpecTests {
    variantPrefixes = ['Plain', 'Text', 'Spatial']
    variantBaseClasses = ['PlainBase', 'TextBase'] // missing Spatial
    variantSpecFilePatterns = ['**/plain*.csv-spec', '**/text*.csv-spec', '**/spatial*.csv-spec']
}

// after
generateEsqlSpecTests {
    variantPrefixes = ['Plain', 'Text', 'Spatial']
    variantBaseClasses = ['PlainBase', 'TextBase', 'SpatialBase']
    variantSpecFilePatterns = ['**/plain*.csv-spec', '**/text*.csv-spec', '**/spatial*.csv-spec']
}
Defensive patterns

Strategy: validation

Validate before calling

// Assert list sizes at configuration time
assert variantPrefixes.get().size() == variantBaseClasses.get().size() :
    'variantPrefixes and variantBaseClasses must have the same size'
assert variantPrefixes.get().size() == variantSpecFilePatterns.get().size() :
    'variantPrefixes and variantSpecFilePatterns must have the same size'

Prevention

When it happens

Trigger: The task is configured with mismatched list sizes for its variant properties. For example, variantPrefixes has 2 entries, variantBaseClasses has 3, and variantSpecFilePatterns has 2. This is a configuration-time error that surfaces at task execution time when the properties are read.

Common situations: A build engineer adds a new variant to variantPrefixes but forgets to add the corresponding entry in variantBaseClasses or variantSpecFilePatterns. The properties are configured from different sources (one from a file, another from a hardcoded list) that drift in length. Copy-paste error when duplicating a variant configuration block.

Related errors


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