hucsmn opened a new issue, #1626:
URL: https://github.com/apache/logging-log4j2/issues/1626
## Description
Message pattern `"\\\\{}"` causes `ArrayIndexOutOfBoundsException` if
ParameterizedMessage.init()
## Configuration
Default spring boot configuration.
**Version:** [Log4j version]
Known reproducable versions: 2.12.0 - 2.20.0
**Operating system:** [OS and version]
Windows 10
**JDK:** [JDK distribution and version]
Oracle JDK 1.8u362
## Logs
```
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at
org.apache.logging.log4j.message.ParameterFormatter.countArgumentPlaceholders2(ParameterFormatter.java:121)
at
org.apache.logging.log4j.message.ParameterizedMessage.init(ParameterizedMessage.java:149)
at
org.apache.logging.log4j.message.ParameterizedMessage.<init>(ParameterizedMessage.java:123)
at
org.apache.logging.log4j.message.ParameterizedMessage.<init>(ParameterizedMessage.java:132)
at
org.apache.logging.log4j.message.ParameterizedMessageFactory.newMessage(ParameterizedMessageFactory.java:70)
at
org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2033)
at
org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1899)
at org.apache.logging.slf4j.Log4jLogger.error(Log4jLogger.java:304)
......
```
## Reproduction
```java
package org.apache.logging.log4j.message;
public class Test {
private static final String testMsg1 = "\\\\{}";
private static final String testMsg2 = "\\\\{} blabla";
private static final String[] testArgs = {"a"};
public static void main(String[] args) {
System.out.println(formatUsingReusableParameterizedMessage(testMsg2)); // \a
blabla
System.out.println(formatUsingParameterizedMessage(testMsg2));
// \a blabla
System.out.println(formatUsingReusableParameterizedMessage(testMsg1)); // \a
System.out.println(formatUsingParameterizedMessage(testMsg1));
// throws ArrayIndexOutOfBoundsException
}
public static String formatUsingParameterizedMessage(final String msg) {
return new ParameterizedMessage(msg, testArgs).getFormattedMessage();
}
public static String formatUsingReusableParameterizedMessage(final
String msg) {
return new ReusableParameterizedMessage().set(msg,
testArgs).getFormattedMessage();
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]