Skip to content

fix: treat null parameters as empty in CsvParameterLayout - #4245

Open
arimu1 wants to merge 1 commit into
apache:2.xfrom
arimu1:fix/4243-csv-parameter-layout-null-params
Open

fix: treat null parameters as empty in CsvParameterLayout#4245
arimu1 wants to merge 1 commit into
apache:2.xfrom
arimu1:fix/4243-csv-parameter-layout-null-params

Conversation

@arimu1

@arimu1 arimu1 commented Aug 6, 2026

Copy link
Copy Markdown

Fixes #4243

Description

CsvParameterLayout.toSerializable passes Message.getParameters() to CSVFormat.printRecord without a null check. Parameter-less messages such as SimpleMessage return null from getParameters(), and Commons CSV throws NullPointerException when the values array is null. Only IOException is caught, so the NPE escapes to the appender and the event is lost.

This change treats a null parameter array as Constants.EMPTY_OBJECT_ARRAY, which produces a well-formed empty CSV record (record separator only) and matches the zero-length parameters case.

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

Testing

  • JDK 17 (branch enforcer requires [17,18))
  • ./mvnw test -pl :log4j-core-test -am -Dtest=CsvParameterLayoutTest#testNullParametersProduceEmptyRecord -Dsurefire.failIfNoSpecifiedTests=false2/2 pass
  • Related existing layout tests in the same class (testLayoutDefaultNormal, testLayoutDefaultObjectArrayMessage, testLayoutTab, charset/content-type tests) also pass
  • Spotless check clean on :log4j-core and :log4j-core-test

SimpleMessage and other parameter-less Message implementations return
null from getParameters(). Commons CSV printRecord NPEs on a null values
array, so plain logger.info("text") events failed the layout. Use
Constants.EMPTY_OBJECT_ARRAY so an empty CSV record is emitted instead.

Fixes apache#4243

Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

CsvParameterLayout throws NullPointerException on any event without parameters

1 participant