Skip to content

[Bug] The replaceParam method of AbstractLogger behaves unexpectedly when the replaced string contains a replacement marker #13591

@shichaoyuan

Description

@shichaoyuan

Search before asking

  • I had searched in the issues and found no similar issues.

Apache SkyWalking Component

Java Agent (apache/skywalking-java)

What happened

The replaceParam method of AbstractLogger behaves unexpectedly when the replaced string contains a replacement marker.

What you expected to happen

log.info("sample rule update: {} -> {}", "Config{a={}}", "Config{b={}}")

expect: sample rule update: Config{a={}} -> Config{b={}}

but actual: sample rule update: Config{a=Config{b={}}} -> {}

How to reproduce

just run code above

Anything else

https://github.com/apache/skywalking-java/blob/67ab8b222fbb9a71b450665eb9f733380d813b8a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/AbstractLogger.java#L185-L203

            tmpMessage = tmpMessage.replaceFirst("\\{\\}", Matcher.quoteReplacement(String.valueOf(parameters[parametersIndex++])));
            startSize = index + 2;

The index should not just increase by 2, but should increase by the length of the string to be replaced.

Are you willing to submit a pull request to fix on your own?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    agentLanguage agent related.bugSomething isn't working and you are sure it's a bug!javaJava agent related

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions