{"record":{"id":"392d375ab91c3994","repo":"junit-team/junit5","slug":"class-must-not-be-null-392d37","errorCode":null,"errorMessage":"Class must not be null","messagePattern":"Class must not be null","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-platform-commons/src/main/java/org/junit/platform/commons/logging/LoggerFactory.java","lineNumber":50,"sourceCode":"\n\tprivate LoggerFactory() {\n\t\t/* no-op */\n\t}\n\n\tprivate static final Set<LogRecordListener> listeners = ConcurrentHashMap.newKeySet();\n\n\t/**\n\t * Get a {@link Logger} for the specified class.\n\t *\n\t * @param clazz the class for which to get the logger; never {@code null}\n\t * @return the logger\n\t */\n\t@SuppressWarnings(\"ConstantValue\")\n\tpublic static Logger getLogger(Class<?> clazz) {\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 (clazz == null) {\n\t\t\tthrow new JUnitException(\"Class must not be null\");\n\t\t}\n\n\t\treturn new DelegatingLogger(clazz.getName());\n\t}\n\n\t/**\n\t * Add the supplied {@link LogRecordListener} to the set of registered\n\t * listeners.\n\t */\n\tpublic static void addListener(LogRecordListener listener) {\n\t\tlisteners.add(listener);\n\t}\n\n\t/**\n\t * Remove the supplied {@link LogRecordListener} from the set of registered\n\t * listeners.\n\t */\n\tpublic static void removeListener(LogRecordListener listener) {","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-commons/src/main/java/org/junit/platform/commons/logging/LoggerFactory.java#L32-L68","documentation":"Thrown by LoggerFactory.getLogger(Class) when clazz is null. Because LoggerFactory cannot use Preconditions (package cycle), it checks directly and raises JUnitException 'Class must not be null' before constructing a DelegatingLogger with the class name.","triggerScenarios":"Calling LoggerFactory.getLogger((Class<?>) null). The `if (clazz == null)` guard fires.","commonSituations":"Passing a Class reference obtained from a lookup that returned null. Generic helper code losing the class token before calling getLogger. Static initialization where the class field is not yet set.","solutions":["Pass a concrete Class object such as LoggerFactory.getLogger(MyService.class).","Null-check the Class before calling getLogger and raise a clearer error if absent.","Use the String overload LoggerFactory.getLogger(String) if only a name is available."],"exampleFix":"// before\nLogger log = LoggerFactory.getLogger(clazz); // clazz may be null\n\n// after\nLogger log = LoggerFactory.getLogger(MyService.class);","handlingStrategy":"validation","validationCode":"Class<?> clazz = resolveClass();\nif (clazz == null) throw new IllegalArgumentException(\"Class required\");\nLoggerFactory.getLogger(clazz);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass the concrete Class token to getLogger(Class).","Use getLogger(String) when only a name is available.","Avoid forwarding possibly-null Class references."],"tags":["junit-platform","logging","null-check","logger-factory"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}