Skip to content

Handle missing stack traces in ExtendedThreadInformation #3655

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

Merged
merged 4 commits into from
May 19, 2025
Merged

Conversation

PAX523
Copy link
Contributor

@PAX523 PAX523 commented May 8, 2025

Fix ArrayIndexOutOfBoundsException on invocation of Message.getFormattedMessage() when any thread has no stack trace, which occurs on some JVM implementations.

See issue: #3214

The mentioned method retrieves detail information about all existing threads and collects it in a result string. One of the information are the stack traces. Some JVM implementations (such as OpenJ9) have an empty stack trace of threads in a specific state. This, in turn, results in a ArrayIndexOutOfBoundsException if the user tries to dump all thread information via org.apache.logging.log4j.message.ThreadDumpMessage.ThreadDumpMessage(String).

Checklist

  • Base your changes on 2.x branch if you are targeting Log4j 2; use main otherwise
  • ./mvnw verify succeeds (if it fails due to code formatting issues reported by Spotless, simply run ./mvnw spotless:apply and retry)
  • Non-trivial changes contain an entry file in the src/changelog/.2.x.x directory
  • Tests for the changes are provided
  • Commits are signed (optional, but highly recommended)

Copy link

github-actions bot commented May 8, 2025

Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 Build Scan PUBLISHED
Generated by gradle/develocity-actions

@ppkarwasz ppkarwasz moved this from To triage to In review in Log4j bug tracker May 9, 2025
Copy link
Member

@vy vy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PAX523, thanks so much for the fix! It is a pleasure to collaborate with an external contributor knowing how to write tests and adhere to existing coding style. 🙇

I've dropped some minor remarks. If you can address those, the rest LGTM.

@vy vy self-assigned this May 9, 2025
@vy vy moved this from In review to Waiting for user in Log4j bug tracker May 9, 2025
@PAX523
Copy link
Contributor Author

PAX523 commented May 12, 2025

@PAX523, thanks so much for the fix! It is a pleasure to collaborate with an external contributor knowing how to write tests and adhere to existing coding style. 🙇

I've dropped some minor remarks. If you can address those, the rest LGTM.

Thanks for your warm words. I've just applied the changes.

@PAX523 PAX523 requested a review from vy May 13, 2025 08:07
@PAX523
Copy link
Contributor Author

PAX523 commented May 15, 2025

Hallo @vy, it's ready for review again

@vy
Copy link
Member

vy commented May 15, 2025

@PAX523, we have recently changed our CI workflows, all commits must be signed. Would you mind signing your commits (using -S in Git) and force-pushing them, please?

@PAX523 PAX523 force-pushed the 2.x branch 2 times, most recently from ca7ad63 to 3611e9f Compare May 16, 2025 04:38
PAX523 added 3 commits May 16, 2025 06:39
Fix ArrayIndexOutOfBoundsException on invocation of Message.getFormattedMessage() when any thread has no stack trace, which occurs on some JVM implementations.
Updated `getStackTraceElement` to return null instead of a placeholder when stack trace is empty. Added null checks to ensure safety when accessing class name and method name, and replaced string comparisons with null-safe constants.

$ Please enter the commit message for your changes. Lines starting
$ with '$' will be kept; you may remove them yourself if you want to.
$ An empty message aborts the commit.
$
$ Date:      Mon May 12 07:03:30 2025 +0200
$
$ On branch 2.x
$ Your branch is up to date with 'origin/2.x'.
$
$ Changes to be committed:
$	modified:   log4j-core/src/main/java/org/apache/logging/log4j/core/message/ExtendedThreadInformation.java
$
@PAX523
Copy link
Contributor Author

PAX523 commented May 16, 2025

@vy phew... it's done!

@PAX523
Copy link
Contributor Author

PAX523 commented May 19, 2025

Good morning @vy. What's the expected workflow now? When will this PR be merged?

@vy vy merged commit 2bc484c into apache:2.x May 19, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from Waiting for user to Done in Log4j bug tracker May 19, 2025
@vy
Copy link
Member

vy commented May 19, 2025

@PAX523, thanks so much.

What's the expected workflow now?

Maintainers finding time to check the commits are not tampered, kick CI, and get it merged upon success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants