junit-team/junit5 · error · PreconditionViolationException
${message}
Error message
${message} What it means
Generic PreconditionViolationException thrown by Preconditions.condition(boolean, String) when the boolean predicate is false. The literal message passed by the caller is used verbatim - it is not a JUnit-internal message. Hundreds of call sites use this method, so the exact meaning depends entirely on the calling context shown in the stack trace.
Source
Thrown at junit-platform-commons/src/main/java/org/junit/platform/commons/util/Preconditions.java:373
public static String notBlank(@Nullable String str, Supplier<String> messageSupplier)
throws PreconditionViolationException {
condition(StringUtils.isNotBlank(str), messageSupplier);
return str;
}
/**
* Assert that the supplied {@code predicate} is {@code true}.
*
* @param predicate the predicate to check
* @param message precondition violation message
* @throws PreconditionViolationException if the predicate is {@code false}
* @see #condition(boolean, Supplier)
*/
@Contract("false, _ -> fail")
public static void condition(boolean predicate, String message) throws PreconditionViolationException {
if (!predicate) {
throw new PreconditionViolationException(message);
}
}
/**
* Assert that the supplied {@code predicate} is {@code true}.
*
* @param predicate the predicate to check
* @param messageSupplier precondition violation message supplier
* @throws PreconditionViolationException if the predicate is {@code false}
*/
@Contract("false, _ -> fail")
public static void condition(boolean predicate, Supplier<String> messageSupplier)
throws PreconditionViolationException {
if (!predicate) {
throw new PreconditionViolationException(messageSupplier.get());
}
}View on GitHub (pinned to f070c699a0)
Solutions
- Read the message - it states the specific precondition that failed
- Find the Preconditions.condition call site in the stack trace to see which contract was violated
- Fix the caller to satisfy the documented precondition
Defensive patterns
Strategy: validation
Prevention
- Read the PreconditionViolationException message and the call site in the stack trace
- Honour documented @param contracts on JUnit public APIs
- Avoid calling org.junit.platform.commons.util internal classes directly
When it happens
Trigger: Any internal JUnit call to Preconditions.condition(predicate, "msg") where predicate evaluates false - e.g. a public API called with an argument that violates a documented contract that this guard checks.
Common situations: Misuse of a JUnit public API (wrong selector, malformed unique ID, invalid filter); calling internal utility methods directly with bad inputs; extension/SPI implementations violating documented invariants.
Related errors
- ${messageSupplier.get()}
- @DefaultLocale not configured correctly. When not using a la
- Configuration error: %s.
- %d configuration errors:%n%s
- Pattern compilation failed for a regular expression supplied
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/f29d74d7c4dc6aef.
Report an issue: GitHub.