Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-397

Bridge can still call underlying logging system with a null message.

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.7.24
    • jul-to-slf4j
    • 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.

      Attachments

        Activity

          People

            slf4j-dev SLF4J developers list
            jhuxhorn Joern Huxhorn
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: