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

LoggerWrapper and subclasses perform argument substitution twice

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 2.0.0-alpha2
    • 1.7.x
    • slf4j-ext
    • Java 8; haven't tested with earlier versions or Java 9.

    Description

      If a String containing "{}" (alone or with other characters) is passed to a LoggerWrapper log method that takes a format string and arguments, or to a subclass method that follows the same pattern, a situation can occur where an argument is substituted into the place of the argument containing the substitution brackets. That argument may be another string preceding the string with brackets, or if the string with brackets is first, it may be that argument itself.

      This also occurs with log methods following this pattern even when a string format message is not expected, such as with XLogger entry and exit methods or LoggerWrapper single argument methods.

      It's hard to describe effectively, so I'll provide some examples and test cases to help.

      Brackets Second
      log.error("{},{}", foo, "[{}]");
      // Expected
      [ERROR] ReproduceSlf4jBug - foo,[{}]
      // Actual
      [ERROR] ReproduceSlf4jBug - foo,[foo]
      
      Brackets First
      log.error("{},{}", "[{}]", foo);
      // Expected
      [ERROR] ReproduceSlf4jBug - [{}],foo
      // Actual
      [ERROR] ReproduceSlf4jBug - [[{}]],foo
      

      In the attached tests, a basic org.slf4j.Logger is tested with the same arguments to provide a reference.

      Attachments

        1. results.txt
          2 kB
        2. ReproduceSlf4jExtBug.java
          2 kB
        3. log4j2.xml
          0.3 kB

        Activity

          People

            ceki Ceki Gülcü
            kec Kristin Clemens
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: