{"record":{"id":"89547b6039983445","repo":"alibaba/druid","slug":"logger-can-not-be-null","errorCode":null,"errorMessage":"logger can not be null","messagePattern":"logger can not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"core/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLoggerImpl.java","lineNumber":70,"sourceCode":"        String property = properties.getProperty(\"druid.stat.loggerName\");\n        if (property != null && property.length() > 0) {\n            setLoggerName(property);\n        }\n    }\n\n    public Log getLogger() {\n        return logger;\n    }\n\n    @Override\n    public void setLoggerName(String loggerName) {\n        logger = LogFactory.getLog(loggerName);\n    }\n\n    @Override\n    public void setLogger(Log logger) {\n        if (logger == null) {\n            throw new IllegalArgumentException(\"logger can not be null\");\n        }\n        this.logger = logger;\n    }\n\n    public boolean isLogEnable() {\n        return logger.isInfoEnabled();\n    }\n\n    public void log(String value) {\n        logger.info(value);\n    }\n\n    @Override\n    public void log(DruidDataSourceStatValue statValue) {\n        if (!isLogEnable()) {\n            return;\n        }\n        Map<String, Object> map = new LinkedHashMap<String, Object>();","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/alibaba/druid/blob/fa8dc9912637a2f729eef9f55356621fec18d40e/core/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLoggerImpl.java#L52-L88","documentation":"IllegalArgumentException thrown by DruidDataSourceStatLoggerImpl.setLogger(Log) when the argument is null. The stat logger is mandatory (every log/info call dereferences it), so a null logger would cause NPEs later; the setter fails fast instead.","triggerScenarios":"statLogger.setLogger(null) called directly, or a configuration path that resolves a logger name to null and then calls setLogger(null). The guard at line 68-70 throws.","commonSituations":"Spring XML/YAML wiring a null logger bean; programmatic config where the logger field was never assigned; a property placeholder (e.g. ${druid.stat.logger}) resolving to empty/null; custom monitoring setup constructing the stat logger manually.","solutions":["Pass a non-null org.apache.commons.logging.Log (e.g. LogFactory.getLog(\"DruidDataSourceStat\")).","Prefer setLoggerName(String) which resolves the Log itself and will not be null for a valid name.","If the logger should be optional in your wiring, default to a no-op Log (or StdOut) instead of null."],"exampleFix":"// before\nstatLogger.setLogger(null); // IllegalArgumentException\n\n// after\nimport org.apache.commons.logging.LogFactory;\nstatLogger.setLogger(LogFactory.getLog(\"DruidStat\"));\n// or\nstatLogger.setLoggerName(\"DruidStat\");","handlingStrategy":"validation","validationCode":"if (logger == null) {\n    throw new IllegalArgumentException(\"logger must be non-null; use setLoggerName if unsure\");\n}\nstatLogger.setLogger(logger);","typeGuard":"// ensure a non-null Log before assignment\njava.util.function.Supplier<Log> safe = () ->\n    logger != null ? logger : LogFactory.getLog(\"DruidStat\");\nstatLogger.setLogger(safe.get());","tryCatchPattern":null,"preventionTips":["Prefer setLoggerName(String) over setLogger(Log) — it resolves the Log internally.","Default any optional logger wiring to a concrete Log, never null.","Validate Spring placeholders (e.g. ${druid.stat.logger}) are non-empty before binding."],"tags":["validation","stat-logger","argument-check","config","monitoring"],"backgroundTag":null,"analyzedSha":"fa8dc9912637a2f729eef9f55356621fec18d40e","analyzedAt":"2026-08-14T04:55:06.789Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}