[slf4j-dev] [JIRA] (SLF4J-421) LoggerWrapper and subclasses perform argument substitution twice

QOS.CH (JIRA) noreply-jira at qos.ch
Mon Nov 27 18:50:00 CET 2017


    [ https://jira.qos.ch/browse/SLF4J-421?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18980#comment-18980 ] 

Kristin Clemens commented on SLF4J-421:
---------------------------------------

I believe this can be solved by doing some extra work in MessageFormatter's arrayFormat method, before and after calling deeplyAppendParameter. We need to check to see if the current argument contains the formatting anchor, and if so, escape the anchor before appending it. Then we need to remove the argument from the argument array. If no one gets to this before I do, I'll submit a patch myself. Not sure when that'll be, though.

> LoggerWrapper and subclasses perform argument substitution twice 
> -----------------------------------------------------------------
>
>                 Key: SLF4J-421
>                 URL: https://jira.qos.ch/browse/SLF4J-421
>             Project: SLF4J
>          Issue Type: Bug
>          Components: slf4j-ext
>    Affects Versions: 1.7.x
>         Environment: Java 8; haven't tested with earlier versions or Java 9.
>            Reporter: Kristin Clemens
>            Assignee: SLF4J developers list
>              Labels: logging, substitution
>         Attachments: log4j2.xml, ReproduceSlf4jExtBug.java, results.txt
>
>
> 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.
> {code:java|title=Brackets Second|borderStyle=solid}
> log.error("{},{}", foo, "[{}]");
> // Expected
> [ERROR] ReproduceSlf4jBug - foo,[{}]
> // Actual
> [ERROR] ReproduceSlf4jBug - foo,[foo]
> {code}
> {code:java|title=Brackets First|borderStyle=solid}
> log.error("{},{}", "[{}]", foo);
> // Expected
> [ERROR] ReproduceSlf4jBug - [{}],foo
> // Actual
> [ERROR] ReproduceSlf4jBug - [[{}]],foo
> {code}
> *In the attached tests, a basic org.slf4j.Logger is tested with the same arguments to provide a reference.*



--
This message was sent by Atlassian JIRA
(v7.3.1#73012)


More information about the slf4j-dev mailing list