junit-team/junit5 · error · JUnitException
Level must not be null
Error message
Level must not be null
What it means
Thrown by LogRecordListener.stream(Level) when level is null. Because LogRecordListener cannot use Preconditions (package cycle), it checks directly and raises JUnitException 'Level must not be null' before filtering records by that level.
Solutions
- Pass a concrete java.util.logging.Level such as Level.INFO or Level.WARNING.
- Null-check the Level before calling stream(level) and fail the test with a clearer assertion if absent.
- Use the no-Level overload stream() if you want all records.
Example fix
// before assertThat(listener.stream(level)).isEmpty(); // level may be null // after assertThat(listener.stream(Level.INFO)).isEmpty();
Defensive patterns
Strategy: validation
Validate before calling
Level level = resolveLevel();
if (level == null) throw new IllegalArgumentException("Level required");
listener.stream(level); Prevention
- Pass a concrete Level constant to stream(Level).
- Use stream() when no level filtering is needed.
- Null-check Levels computed at runtime.
When it happens
Trigger: Calling listener.stream((Level) null) in a test assertion. The `if (level == null)` guard fires.
Common situations: Passing a Level variable that was not initialized, or computed from a map lookup that returned null. Test helper that forwards a null Level into the listener API.
Related errors
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/cb35e5bb57692b68.
Report an issue: GitHub.
Appendix: source
Thrown at junit-platform-commons/src/main/java/org/junit/platform/commons/logging/LogRecordListener.java:83
* thread at the given log level.
*
* <p>As stated in the Javadoc for {@code LogRecord}, a submitted
* {@code LogRecord} should not be updated by the client application. Thus,
* the {@code LogRecords} in the returned stream should only be inspected for
* testing purposes and not modified in any way.
*
* @param level the log level for which to get the log records; never {@code null}
* @since 1.4
* @see #stream()
* @see #stream(Class)
* @see #stream(Class, Level)
*/
@SuppressWarnings({ "ConstantValue", "ReferenceEquality" })
public Stream<LogRecord> stream(Level level) {
// NOTE: we cannot use org.junit.platform.commons.util.Preconditions here
// since that would introduce a package cycle.
if (level == null) {
throw new JUnitException("Level must not be null");
}
return stream().filter(logRecord -> logRecord.getLevel() == level);
}
/**
* Get a stream of {@link LogRecord log records} that have been
* {@linkplain #logRecordSubmitted submitted} to this listener by the current
* thread for the logger name equal to the name of the given class.
*
* <p>As stated in the Javadoc for {@code LogRecord}, a submitted
* {@code LogRecord} should not be updated by the client application. Thus,
* the {@code LogRecords} in the returned stream should only be inspected for
* testing purposes and not modified in any way.
*
* @param clazz the class for which to get the log records; never {@code null}
* @see #stream()
* @see #stream(Level)View on GitHub (pinned to f070c699a0)