junit-team/junit5 · error · JUnitException
%s must not be null
Error message
%s must not be null
What it means
Thrown by the private checkNotNull in Try when Try.failure(cause) is called with a null cause. Because Try lives in a low-level package that cannot depend on Preconditions (package cycle), it does its own null check and raises JUnitException '<title> must not be null'. The title is 'cause', so the message reads 'cause must not be null'.
Source
Thrown at junit-platform-commons/src/main/java/org/junit/platform/commons/function/Try.java:91
}
/**
* Convert the supplied exception into a failed {@code Try}.
*
* @param cause the exception to wrap; must not be {@code null}
* @return a failed {@code Try} that contains the supplied value; never
* {@code null}
*/
public static <V> Try<V> failure(Exception cause) {
return new Failure<>(checkNotNull(cause, "cause"));
}
// Cannot use Preconditions due to package cycle
@Contract("null, _ -> fail; !null, _ -> param1")
private static <T> T checkNotNull(@Nullable T input, String title) {
if (input == null) {
// Cannot use PreconditionViolationException due to package cycle
throw new JUnitException(title + " must not be null");
}
return input;
}
private static <V> Try<V> of(Callable<Try<V>> action) {
try {
return action.call();
}
catch (Exception e) {
return failure(e);
}
}
private Try() {
/* no-op */
}
/**View on GitHub (pinned to f070c699a0)
Solutions
- Ensure a non-null Exception is passed to Try.failure().
- Null-check the cause before calling Try.failure(), or use Try.success/Try.of instead when there is no error.
- If the cause is genuinely absent, raise an explicit JUnitException with a descriptive message instead of null.
Example fix
// before
Try<V> result = Try.failure(someThrowable); // someThrowable may be null
// after
Try<V> result = (someThrowable instanceof Exception e)
? Try.failure(e)
: Try.failure(new JUnitException("underlying error was not an Exception")); Defensive patterns
Strategy: validation
Validate before calling
// Never pass a null cause to Try.failure()
Exception cause = resolveCause();
if (cause == null) throw new JUnitException("cause must not be null");
Try<V> t = Try.failure(cause); Prevention
- Guarantee non-null Exception when constructing a failed Try.
- Prefer Try.of(Callable) to avoid manual failure construction.
- Add a null check at API boundaries that produce Try results.
When it happens
Trigger: Calling Try.failure(null) directly or via code paths that pass a null exception into failure(). The checkNotNull guard in failure() trips before a Failure is constructed.
Common situations: Library/extension code constructing a Try from a possibly-null exception without null-checking first. Misuse of Try APIs in custom extensions. Unlikely to be hit by end users directly; more common in framework-adjacent code.
Related errors
- %s must not be null
- %s must not be null
- Level must not be null
- Class must not be null
- Class must not be null
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/dcc962edc862dbdc.
Report an issue: GitHub.