Skip to content

Fix empty string handling for TruncatingBufferedWriter #2609

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 27, 2024

Conversation

bayne
Copy link
Contributor

@bayne bayne commented May 23, 2024

ERROR StatusConsoleListener An exception occurred processing Appender console
 java.lang.IndexOutOfBoundsException: invalid offset: 0
	at org.apache.logging.log4j.layout.template.json.util.TruncatingBufferedWriter.write(TruncatingBufferedWriter.java:131)
	at java.base/java.io.PrintWriter.write(PrintWriter.java:541)
	at java.base/java.io.PrintWriter.write(PrintWriter.java:558)
	at java.base/java.io.PrintWriter.print(PrintWriter.java:685)
	at com.lowagie.text.ExceptionConverter.printStackTrace(ExceptionConverter.java:162)
	at org.apache.logging.log4j.layout.template.json.resolver.StackTraceStringResolver.resolve(StackTraceStringResolver.java:80)
	at org.apache.logging.log4j.layout.template.json.resolver.ExceptionResolver.lambda$createStackTraceStringResolver$3(ExceptionResolver.java:302)
	at org.apache.logging.log4j.layout.template.json.resolver.ExceptionResolver.resolve(ExceptionResolver.java:445)
	at org.apache.logging.log4j.layout.template.json.resolver.ExceptionResolver.resolve(ExceptionResolver.java:188)
	at org.apache.logging.log4j.layout.template.json.resolver.TemplateResolver.resolve(TemplateResolver.java:66)
	at org.apache.logging.log4j.layout.template.json.resolver.TemplateResolvers$4.resolve(TemplateResolvers.java:284)
...

The client code assumes empty strings will not result in an exception being thrown

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)

@vy vy self-assigned this May 23, 2024
@vy vy added the bug Incorrect, unexpected, or unintended behavior of existing code label May 23, 2024
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.

@bayne, thanks so much for the report, fix, and tests! Much appreciated! 🙇

I removed if (end == 0) along with a test case, since it is making append() unnecessarily more lenient and breaking a test.

Could you also create a /src/changelog/.2.x.x/fix-TruncatingBufferedWriter-empty-input-handling.xml, please? (You can copy 2379_fix_message_factory_properties.xml and adapt it.)

@vy vy changed the title Update empty string handling for TruncatingBufferedWriter Fix empty string handling for TruncatingBufferedWriter May 24, 2024
@vy vy added this to the 2.24.0 milestone May 27, 2024
@vy vy merged commit 8ccc130 into apache:2.x May 27, 2024
6 checks passed
vy added a commit that referenced this pull request May 27, 2024
Co-authored-by: Volkan Yazıcı <volkan@yazi.ci>
@bayne bayne deleted the handle-empty-string branch May 29, 2024 14:54
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants