Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException on invocation of org.apache.logging.log4j.message.Message.getFormattedMessage() #3214

Open
PAX523 opened this issue Nov 18, 2024 · 0 comments
Labels
bug Incorrect, unexpected, or unintended behavior of existing code waiting-for-maintainer

Comments

@PAX523
Copy link

PAX523 commented Nov 18, 2024

Description

It occurs depending on the Java version and the used JVM implementation. We're migrating from Java 8 to Java 17. I cannot reproduce it with Oracle JDK 8, but with OpenJ9 JDK 8. The problem is that there are threads with an empty stacktrace which is not expected by ExtendedThreadInformation.

Configuration

Version: 2.17.2

Operating system: N/A

JDK: 17.0.3_7_openj9

Logs

java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
	at org.apache.logging.log4j.core.message.ExtendedThreadInformation.formatState(ExtendedThreadInformation.java:141)
	at org.apache.logging.log4j.core.message.ExtendedThreadInformation.printThreadInfo(ExtendedThreadInformation.java:44)
	at org.apache.logging.log4j.message.ThreadDumpMessage.formatTo(ThreadDumpMessage.java:98)
	at org.apache.logging.log4j.message.ThreadDumpMessage.getFormattedMessage(ThreadDumpMessage.java:86)
	at de.icongmbh.dopix.logging.log4j.TestLog4jLogManager.dumpAllThreads_loggerIsEnabled_generateLogEvent(TestLog4jLogManager.java:293)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)

Reproduction

    ExtendedLogger loggerLogger = mock(ExtendedLogger.class, "loggerLogger");
    when(this.contextResolver.get()).thenReturn(this.context);
    when(this.context.getLogger(Log4jLogManager.class.getName())).thenReturn(this.loggerLogger);
    when(this.configFactory.create(any(LoggerContext.class))).thenReturn(this.config);
    this.subjectUnderTest = new Log4jLogManager(this.contextResolver, this.configFactory);
    verify(this.configFactory, atLeastOnce()).create(this.context);
    when(this.context.getLogger(LOGGER_NAME)).thenReturn(this.logger);

    when(this.loggerLogger.isEnabled(isA(Level.class), isA(Marker.class))).thenReturn(true);

    assertThat(this.subjectUnderTest.dumpAllThreads(CATEGORIES_MASK)).isTrue();

    final ArgumentCaptor<Message> message = ArgumentCaptor.forClass(Message.class);
    verify(this.loggerLogger).logMessage(eq(RESULTING_LEVEL),
                                         eq(RESULTING_MARKER),
                                         eq(Log4jLogManager.FQCN),
                                         any(StackTraceElement.class),
                                         message.capture(),
                                         ArgumentMatchers.<Throwable> isNull());
    assertThat(message.getValue().getFormattedMessage()).contains(Thread.currentThread().getName());
@ppkarwasz ppkarwasz added the bug Incorrect, unexpected, or unintended behavior of existing code label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect, unexpected, or unintended behavior of existing code waiting-for-maintainer
Projects
None yet
Development

No branches or pull requests

2 participants