Skip to content

Comments

fix: Pattern Layout throwable use Throwable.toString()#4033

Open
JongminChung wants to merge 2 commits intoapache:2.xfrom
JongminChung:fix/#4019
Open

fix: Pattern Layout throwable use Throwable.toString()#4033
JongminChung wants to merge 2 commits intoapache:2.xfrom
JongminChung:fix/#4019

Conversation

@JongminChung
Copy link

@JongminChung JongminChung commented Jan 23, 2026

Align renderThrowableMessage(...) to use Throwable.toString(), restoring the default printStackTrace() behavior documented for the %ex converter.


Checklist

  • Base your changes on 2.x branch if you are targeting Log4j 2; use main otherwise
  • ./mvnw verify succeeds (the build instructions)
  • Non-trivial changes contain an entry file in the src/changelog/.2.x.x directory
  • Tests are provided

@JongminChung
Copy link
Author

Hi, @vy

Would love to get your eyes on this when you get a moment.
Let me know if any changes are needed. Thanks!

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.

Could you add a changelog entry and make sure ./mvnw verify -pl :log4j-core,:log4j-core-test passes, please?

return convert(pattern, EXCEPTION);
}

static String convert(final String pattern, final Throwable throwable) {
Copy link
Member

Choose a reason for hiding this comment

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

This can be private.

Copy link
Author

Choose a reason for hiding this comment

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

This can't be private since it's accessed from other classes within the same package.

(Link)

}
}

private static final class CustomException extends Exception {
Copy link
Member

Choose a reason for hiding this comment

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

Could you implement the following changes, please?

  1. Rename this to ToStringOverridingException
  2. Use super(EXCEPTION) in ctor, and receive no arguments
  3. Create ToStringOverridingException.INSTANCE field and use it (similar to TestFriendlyException.INSTANCE)
  4. Return a constant in toString(), e.g., return "foo"

Copy link
Author

@JongminChung JongminChung Feb 19, 2026

Choose a reason for hiding this comment

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

Thanks for the review, @vy! I've applied all your suggestions:

  1. Renamed to ToStringOverridingException
  2. Changed constructor to use super(EXCEPTION) with no arguments
  3. Added ToStringOverridingException.INSTANCE static field (following TestFriendlyException.INSTANCE pattern)
  4. toString() now returns a constant ("foo")

image

@github-project-automation github-project-automation bot moved this to Changes requested in Log4j pull request tracker Feb 16, 2026
@vy
Copy link
Member

vy commented Feb 16, 2026

Could you replace the entire AI slop description with a short meaningful summary, please?

@github-actions
Copy link

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

Signed-off-by: Jongmin Chung <chungjm0711@gmail.com>
Signed-off-by: Jongmin Chung <chungjm0711@gmail.com>
@JongminChung
Copy link
Author

Could you replace the entire AI slop description with a short meaningful summary, please?

As this is my first PR, I wanted to provide more background context. I've shortened it now.
Thanks for the thorough review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Changes requested

Development

Successfully merging this pull request may close these issues.

2 participants