{"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/956246301e03d757539f7b76dd5a91f298637563/junit-platform-commons/src/main/java/org/junit/platform/commons/logging/LoggerFactory.java#L32-L68","documentation":"LoggerFactory.getLogger(Class<?>) throws JUnitException when clazz is null; it uses clazz.getName() as the logger name. The factory is @INTERNAL and not part of the public API.","triggerScenarios":"Calling LoggerFactory.getLogger(null), typically from internal JUnit code or a plugin reusing the internal LoggerFactory.","commonSituations":"Internal code path that resolved a class to null; third-party integration using the internal logging API with a null class.","solutions":["Pass a concrete Class to getLogger.","Null-check the class before calling.","Prefer java.util.logging.Logger.getLogger(name) directly in non-JUnit code."],"exampleFix":"// before\nLoggerFactory.getLogger(maybeNull);\n\n// after\nLoggerFactory.getLogger(MyService.class);","handlingStrategy":"validation","validationCode":"Class<?> clazz = null;\nif (clazz == null) {\n    throw new IllegalArgumentException(\"Class must not be null\");\n}\nLoggerFactory.getLogger(clazz);","typeGuard":"static <T> Class<T> requireClass(Class<T> c) {\n    return java.util.Objects.requireNonNull(c, \"Class must not be null\");\n}","tryCatchPattern":"try {\n    LoggerFactory.getLogger(clazz);\n} catch (JUnitException e) {\n    if (e.getMessage().equals(\"Class must not be null\")) {\n        // pass a concrete Class\n    } else throw e;\n}","preventionTips":["Pass the class literal directly to getLogger.","Prefer java.util.logging.Logger.getLogger(name) in non-JUnit code.","Treat LoggerFactory as internal and avoid depending on it externally."],"tags":["junit","platform-commons","logging","internal-api","null-check"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}