Skip to content

Fix HTTP appender handling of invalid evaluated headers - #4360

Merged
ramanathan1504 merged 5 commits into
apache:2.xfrom
efegokdemir:codex/issue-4352-skip-invalid-http-header
Oct 20, 2026
Merged

ramanathan1504 merged 5 commits into
apache:2.xfrom
efegokdemir:codex/issue-4352-skip-invalid-http-header

Conversation

@efegokdemir

Copy link
Copy Markdown
Contributor

Summary

An evaluated HTTP appender header can contain a line break from runtime context data. HttpURLConnection rejects that value with IllegalArgumentException, which previously aborted the append and dropped the complete log event.

This change skips only the invalid header, logs a warning, and continues sending the event.

Changes

  • Handle invalid evaluated header values per header instead of aborting the request.
  • Add a WireMock regression covering a runtime header containing a line break and verifying the event is still delivered.

Testing

  • JAVA_HOME=/opt/homebrew/Cellar/openjdk@17/17.0.20.1/libexec/openjdk.jdk/Contents/Home PATH="$JAVA_HOME/bin:$PATH" mvn -pl log4j-core-test -am test-compile org.apache.maven.plugins:maven-surefire-plugin:3.5.2:test@default-test -Dtest=HttpAppenderTest -Dsurefire.failIfNoSpecifiedTests=false -Dspotless.check.skip=true -Dspotless.apply.skip=true — passed (8 tests)
  • JAVA_HOME=/opt/homebrew/Cellar/openjdk@17/17.0.20.1/libexec/openjdk.jdk/Contents/Home PATH="$JAVA_HOME/bin:$PATH" mvn -pl log4j-core-test,log4j-core -am spotless:check — passed
  • git diff --check — passed

AI assistance was used during implementation; the submitted change and validation were reviewed for this contribution.

Fixes #4352

@ramanathan1504 ramanathan1504 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The try/catch in HttpURLConnectionManager keeps the event when ${ctx:tenant} has a line break, and the new test fails without it.
The LOGGER.warn line has no test yet, so can the test also check the status listener for it (suggestion inline)? Please also add a fixed entry for #4352 under src/changelog/.2.x.x/.

Assisted-by: Codex (GPT-5)
Signed-off-by: Efe Gökdemir <efe@rexcode.co.uk>
@efegokdemir

Copy link
Copy Markdown
Contributor Author

Updated in 8e37b08. The invalid-header regression now captures the status listener and verifies the warning for the skipped X-Tenant header. Added the requested #4352 fixed changelog entry.

git diff --check passes. The focused Maven test could not run locally because this environment only has Java 8, while the Maven wrapper requires --add-exports; the branch is pushed for CI validation.

@ramanathan1504 ramanathan1504 added bug Incorrect, unexpected, or unintended behavior of existing code java Pull requests that update Java code appenders Affects one or more Appender plugins labels Sep 29, 2026
@ramanathan1504

ramanathan1504 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

@efegokdemir Thanks for contributing. Before committing a code or adding comments, can you please check the Building.adoc Instructions. And also check all the reviewed comments are figured out. here you are not applied spotless and one other pr also you missed some review points or not fixed correctly. can You check once again all the new commits in respective PRs. And let me know Thanks!👍🏾

@efegokdemir

Copy link
Copy Markdown
Contributor Author

Re-audited #4360, #4359, and #4358 against their current heads after reading building.adoc.

I ran the repository Spotless command (./mvnw -DskipTests -pl :log4j-core,:log4j-core-test spotless:check) for all three branches. It cannot start in this environment because only Java 8 is installed and the wrapper requires JDK 17+ (--add-exports is unsupported by Java 8). No new source changes were needed after the audit.

@efegokdemir

Copy link
Copy Markdown
Contributor Author

Re-audited #4358, #4359, and #4360 against their current heads and followed BUILDING.adoc with JDK 17.

The auxiliary test-without-jackson-databind execution is incompatible with forcing HttpAppenderTest via -Dtest and fails because WireMock cannot load Jackson after that intentional exclusion; the normal execution ran the eight HttpAppenderTest cases successfully.

@ramanathan1504 ramanathan1504 added this to the 2.27.0 milestone Oct 20, 2026

@ramanathan1504 ramanathan1504 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@github-project-automation github-project-automation Bot moved this from Changes requested to Approved in Log4j pull request tracker Oct 20, 2026
@ramanathan1504
ramanathan1504 enabled auto-merge (squash) October 20, 2026 09:23
@ramanathan1504
ramanathan1504 merged commit 96d48ec into apache:2.x Oct 20, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Merged in Log4j pull request tracker Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

appenders Affects one or more Appender plugins bug Incorrect, unexpected, or unintended behavior of existing code java Pull requests that update Java code port-to-2.26.x port-to-main

Projects

Development

Successfully merging this pull request may close these issues.

HTTP appender drops the event when an evaluated header value contains a line break

2 participants