junit-team/junit5 · error · PreconditionViolationException
Configuration error: <error>.
Error message
Configuration error: <error>.
What it means
Thrown by ResolverFacade.configurationErrorOrSuccess() when exactly one validation error is found during @ParameterizedClass field declaration validation or lifecycle method parameter validation. The errors include: duplicate @Parameter indices, negative @Parameter indices, final @Parameter fields, missing sequential indices, or incompatible lifecycle method parameters. The single error is wrapped as 'Configuration error: <error>.'
Source
Thrown at junit-jupiter-params/src/main/java/org/junit/jupiter/params/ResolverFacade.java:386
parameterName(actualDeclaration), parameterIndex));
}
else if (errors.isEmpty()) {
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++) {View on GitHub (pinned to 956246301e)
Solutions
- Read the specific error message after 'Configuration error:' — it identifies the exact field and problem
- Make @Parameter fields non-final (remove final keyword or Lombok val/final annotations)
- Ensure @Parameter indices are sequential starting from 0 with no gaps
- Ensure lifecycle methods (@BeforeEach, @AfterEach, etc.) parameter types match the @ParameterizedClass constructor or field types
Example fix
// before
@ParameterizedClass
@CsvSource("1, 2")
class MyTest {
@Parameter(0) final int a; // final is not allowed
@Parameter(1) int b;
MyTest() { }
}
// after
@ParameterizedClass
@CsvSource("1, 2")
class MyTest {
@Parameter(0) int a; // remove final
@Parameter(1) int b;
MyTest() { }
} Defensive patterns
Strategy: validation
Validate before calling
// Validate @Parameter field declarations at setup time:
static void validateParameterFields(Class<?> testClass) {
Set<Integer> indices = new HashSet<>();
for (Field f : testClass.getDeclaredFields()) {
Parameter p = f.getAnnotation(Parameter.class);
if (p == null) continue;
if (Modifier.isFinal(f.getModifiers()))
throw new IllegalStateException("@Parameter field " + f + " must not be final");
if (!indices.add(p.value()))
throw new IllegalStateException("Duplicate @Parameter(" + p.value() + ")");
}
} Prevention
- Never declare @Parameter fields as final
- Ensure @Parameter indices are sequential: 0, 1, 2, ... with no gaps
- Do not duplicate @Parameter index values across fields
- Run a quick IDE search for '@Parameter' annotations to review field declarations
When it happens
Trigger: Exactly one misconfiguration in a @ParameterizedClass using @Parameter fields: a @Parameter field declared final, two fields with the same @Parameter(index), a @Parameter(-1) on a non-aggregator, a gap in @Parameter indices (e.g., @Parameter(0) and @Parameter(2) with no @Parameter(1)), or a single lifecycle method parameter incompatibility.
Common situations: Declaring @Parameter fields as final (common when using Lombok or records). Skipping an index in a sequence of @Parameter fields. An @AfterEach/@BeforeEach method in a @ParameterizedClass declaring a parameter type incompatible with the class parameter.
Related errors
- %d configuration errors:%n%s
- Constructor injection is not supported for @ParameterizedCla
- Failed to inject parameter value into field: <field>
- Configuration error: You must configure at least one set of
- The display name pattern defined for the parameterized test
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/10ecadcb6bbc818a.json.
Report an issue: GitHub.