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

QOS.CH (JIRA) noreply-jira at qos.ch
Sun Feb 9 18:54:00 CET 2020


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

Jonathan Esssex commented on SLF4J-421:
---------------------------------------

This is surely a colossal headache for anyone doing much work with Json in Java... 

> 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