{"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/956246301e03d757539f7b76dd5a91f298637563/junit-platform-commons/src/main/java/org/junit/platform/commons/logging/LogRecordListener.java#L65-L101","documentation":"LogRecordListener.stream(Level) throws JUnitException when level is null. The API is @INTERNAL (for JUnit's own test suite); it filters captured log records by reference equality on the Level, so a non-null level is required.","triggerScenarios":"Calling listener.stream((Level) null) in a test that asserts on captured JUL records.","commonSituations":"A Level field that resolved to null; refactor that left a null literal; passing a computed Level that returned null.","solutions":["Pass a concrete java.util.logging.Level (e.g. Level.WARNING).","Use stream() without a level argument and filter the records manually.","Run a nullness checker (Checker Framework / IDE inspection) on test code using the listener."],"exampleFix":"// before\nlistener.stream(level);   // level == null\n\n// after\nlistener.stream(Level.WARNING);","handlingStrategy":"validation","validationCode":"java.util.logging.Level level = null; // some computed value\nif (level == null) {\n    throw new IllegalArgumentException(\"Log level must not be null\");\n}\nlistener.stream(level);","typeGuard":"static java.util.logging.Level requireLevel(java.util.logging.Level l) {\n    return java.util.Objects.requireNonNull(l, \"Level must not be null\");\n}","tryCatchPattern":"try {\n    listener.stream(level);\n} catch (JUnitException e) {\n    if (e.getMessage().equals(\"Level must not be null\")) {\n        // pass a concrete Level instead\n    } else throw e;\n}","preventionTips":["Pass java.util.logging.Level constants directly.","Run a nullness checker over test code that uses the internal listener.","Use stream() (no level) and filter manually when the level is dynamic."],"tags":["junit","platform-commons","logging","internal-api","null-check"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}