fix: treat null parameters as empty in CsvParameterLayout - #4245
Open
arimu1 wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4243
Description
CsvParameterLayout.toSerializablepassesMessage.getParameters()toCSVFormat.printRecordwithout a null check. Parameter-less messages such asSimpleMessagereturnnullfromgetParameters(), and Commons CSV throwsNullPointerExceptionwhen the values array is null. OnlyIOExceptionis 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
2.xbranch if you are targeting Log4j 2; usemainotherwise./mvnw verifysucceeds (the build instructions)src/changelog/.2.x.xdirectoryTesting
[17,18))./mvnw test -pl :log4j-core-test -am -Dtest=CsvParameterLayoutTest#testNullParametersProduceEmptyRecord -Dsurefire.failIfNoSpecifiedTests=false— 2/2 passtestLayoutDefaultNormal,testLayoutDefaultObjectArrayMessage,testLayoutTab, charset/content-type tests) also pass:log4j-coreand:log4j-core-test