junit-team/junit5 · error · PreconditionViolationException

%d configuration errors:%n%s

Error message

%d configuration errors:%n%s

What it means

Thrown by ResolverFacade.configurationErrorOrSuccess() when two or more validation errors are found during @ParameterizedClass field declaration or lifecycle method validation. The message includes the error count and a bulleted list of all errors, each on its own line. This aggregates multiple misconfigurations into a single exception so the developer can fix them all at once.

Source

Thrown at junit-jupiter-params/src/main/java/org/junit/jupiter/params/ResolverFacade.java:389

				parameterDeclarationMapping.put(actualDeclaration, originalDeclaration);
			}
		}
		return errors;
	}

	private static String parameterName(ParameterDeclaration actualDeclaration) {
		return actualDeclaration.getParameterName().map(name -> " '" + name + "'").orElse("");
	}

	private static <T> T configurationErrorOrSuccess(List<String> errors, Supplier<T> successfulResult) {
		if (errors.isEmpty()) {
			return successfulResult.get();
		}
		else if (errors.size() == 1) {
			throw new PreconditionViolationException("Configuration error: " + errors.get(0) + ".");
		}
		else {
			throw new PreconditionViolationException("%d configuration errors:%n%s".formatted(errors.size(),
				errors.stream().collect(joining(lineSeparator() + "- ", "- ", ""))));
		}
	}

	private static void validateIndexedParameters(
			NavigableMap<Integer, List<FieldParameterDeclaration>> indexedParameters, List<String> errors) {

		if (indexedParameters.isEmpty()) {
			return;
		}

		indexedParameters.forEach(
			(index, declarations) -> validateIndexedParameterDeclarations(index, declarations, errors));

		for (int index = 0; index <= indexedParameters.lastKey(); index++) {
			if (!indexedParameters.containsKey(index)) {
				errors.add("no field annotated with @Parameter(%d) declared".formatted(index));
			}

View on GitHub (pinned to 956246301e)

Solutions

  1. Read the full error list in the exception message — each error is prefixed with '- ' on its own line
  2. Fix ALL listed errors, not just the first one, since the framework reports them together
  3. Common fixes: remove 'final' from @Parameter fields, ensure sequential indices (0,1,2...), remove duplicate indices
  4. Ensure aggregator fields (@AggregateWith or ArgumentsAccessor type) do not declare a @Parameter index

Example fix

// before
@ParameterizedClass
@CsvSource("1, 2, 3")
class MyTest {
    @Parameter(0) final int a; // error 1: final
    @Parameter(0) int b;       // error 2: duplicate index 0
    @Parameter(2) int c;       // error 3: gap (no index 1)
}

// after
@ParameterizedClass
@CsvSource("1, 2, 3")
class MyTest {
    @Parameter(0) int a;
    @Parameter(1) int b;
    @Parameter(2) int c;
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate all @Parameter fields at once:
static List<String> validateFields(Class<?> testClass) {
    List<String> errors = new ArrayList<>();
    Map<Integer, Field> indices = new TreeMap<>();
    for (Field f : testClass.getDeclaredFields()) {
        Parameter p = f.getAnnotation(Parameter.class);
        if (p == null) continue;
        if (Modifier.isFinal(f.getModifiers())) errors.add(f + " is final");
        if (indices.containsKey(p.value())) errors.add("duplicate index " + p.value());
        indices.put(p.value(), f);
    }
    for (int i = 0; i < indices.size(); i++)
        if (!indices.containsKey(i)) errors.add("missing index " + i);
    return errors;
}

Prevention

When it happens

Trigger: Multiple simultaneous misconfigurations in a @ParameterizedClass: e.g., a final @Parameter field AND a duplicate @Parameter index, or a gap in indices AND a final field. Any combination of two or more errors from validateIndexedParameters, validateAggregatorParameters, or validateLifecycleMethodParameters.

Common situations: Bulk-adding multiple @Parameter fields with several mistakes at once — final fields, index gaps, duplicate indices. Combining @Parameter field issues with lifecycle method parameter incompatibilities in the same class.

Related errors


AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04). Data as JSON: /data/errors/60a09509c1389b85.json. Report an issue: GitHub.