Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
1.7.24
-
None
-
any
-
major
Description
I just found a bug while preparing SLF4J-396.
private String getMessageI18N(LogRecord record) { String message = record.getMessage(); if (message == null) { return null; } // [..] }
should be changed to
private String getMessageI18N(LogRecord record) { String message = record.getMessage(); // can be null! // this is a check to avoid calling the underlying logging system // with a null message. While it is legitimate to invoke j.u.l. with // a null message, other logging frameworks do not support this. // see also http://jira.qos.ch/browse/SLF4J-99 if (message == null) { return ""; } // [..] }
and
public void publish(LogRecord record) { // Silently ignore null records. if (record == null) { return; } Logger slf4jLogger = getSLF4JLogger(record); String message = record.getMessage(); // can be null! // this is a check to avoid calling the underlying logging system // with a null message. While it is legitimate to invoke j.u.l. with // a null message, other logging frameworks do not support this. // see also http://jira.qos.ch/browse/SLF4J-99 if (message == null) { message = ""; } if (slf4jLogger instanceof LocationAwareLogger) { callLocationAwareLogger((LocationAwareLogger) slf4jLogger, record); } else { callPlainSLF4JLogger(slf4jLogger, record); } }
should be changed to
public void publish(LogRecord record) { // Silently ignore null records. if (record == null) { return; } Logger slf4jLogger = getSLF4JLogger(record); if (slf4jLogger instanceof LocationAwareLogger) { callLocationAwareLogger((LocationAwareLogger) slf4jLogger, record); } else { callPlainSLF4JLogger(slf4jLogger, record); } }
The local message variable was assigned but never used. I suspect some refactoring sneakily reintroduced the problematic case where the underlying logging system is called with a null message.
getMessageI18N is called by both callLocationAwareLogger and callPlainSLF4JLogger so this fix should be fine.