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

LoggerWrapper and subclasses perform argument substitution twice

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.x
    • Fix Version/s: 2.0.0-alpha2
    • Component/s: slf4j-ext
    • Environment:

      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. log4j2.xml
          0.3 kB
        2. ReproduceSlf4jExtBug.java
          2 kB
        3. results.txt
          2 kB

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: