{"record":{"id":"cb35e5bb57692b68","repo":"junit-team/junit5","slug":"level-must-not-be-null","errorCode":null,"errorMessage":"Level must not be null","messagePattern":"Level must not be null","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-platform-commons/src/main/java/org/junit/platform/commons/logging/LogRecordListener.java","lineNumber":83,"sourceCode":"\t * thread at the given log level.\n\t *\n\t * <p>As stated in the Javadoc for {@code LogRecord}, a submitted\n\t * {@code LogRecord} should not be updated by the client application. Thus,\n\t * the {@code LogRecords} in the returned stream should only be inspected for\n\t * testing purposes and not modified in any way.\n\t *\n\t * @param level the log level for which to get the log records; never {@code null}\n\t * @since 1.4\n\t * @see #stream()\n\t * @see #stream(Class)\n\t * @see #stream(Class, Level)\n\t */\n\t@SuppressWarnings({ \"ConstantValue\", \"ReferenceEquality\" })\n\tpublic Stream<LogRecord> stream(Level level) {\n\t\t// NOTE: we cannot use org.junit.platform.commons.util.Preconditions here\n\t\t// since that would introduce a package cycle.\n\t\tif (level == null) {\n\t\t\tthrow new JUnitException(\"Level must not be null\");\n\t\t}\n\n\t\treturn stream().filter(logRecord -> logRecord.getLevel() == level);\n\t}\n\n\t/**\n\t * Get a stream of {@link LogRecord log records} that have been\n\t * {@linkplain #logRecordSubmitted submitted} to this listener by the current\n\t * thread for the logger name equal to the name of the given class.\n\t *\n\t * <p>As stated in the Javadoc for {@code LogRecord}, a submitted\n\t * {@code LogRecord} should not be updated by the client application. Thus,\n\t * the {@code LogRecords} in the returned stream should only be inspected for\n\t * testing purposes and not modified in any way.\n\t *\n\t * @param clazz the class for which to get the log records; never {@code null}\n\t * @see #stream()\n\t * @see #stream(Level)","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-commons/src/main/java/org/junit/platform/commons/logging/LogRecordListener.java#L65-L101","documentation":"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.","triggerScenarios":"Calling listener.stream((Level) null) in a test assertion. The `if (level == null)` guard fires.","commonSituations":"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.","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."],"exampleFix":"// before\nassertThat(listener.stream(level)).isEmpty(); // level may be null\n\n// after\nassertThat(listener.stream(Level.INFO)).isEmpty();","handlingStrategy":"validation","validationCode":"Level level = resolveLevel();\nif (level == null) throw new IllegalArgumentException(\"Level required\");\nlistener.stream(level);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass a concrete Level constant to stream(Level).","Use stream() when no level filtering is needed.","Null-check Levels computed at runtime."],"tags":["junit-platform","logging","null-check","test-listener"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}