You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "hucsmn (via GitHub)" <gi...@apache.org> on 2023/07/27 03:26:47 UTC
[I] Specific message pattern causes ArrayIndexOutOfBoundsException throwed by ParameterizedMessage.init() (logging-log4j2)
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: notifications-unsubscribe@logging.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Specific message pattern causes ArrayIndexOutOfBoundsException throwed by ParameterizedMessage.init() (logging-log4j2)
Posted by "vy (via GitHub)" <gi...@apache.org>.
vy closed issue #1626: Specific message pattern causes ArrayIndexOutOfBoundsException throwed by ParameterizedMessage.init()
URL: https://github.com/apache/logging-log4j2/issues/1626
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Specific message pattern causes ArrayIndexOutOfBoundsException throwed by ParameterizedMessage.init() (logging-log4j2)
Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on issue #1626:
URL: https://github.com/apache/logging-log4j2/issues/1626#issuecomment-1655585773
@hucsmn, thanks for the report! This is indeed a bug. I will work on it.
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org