Skip to content

LOG4J2-2530 Generalize check for MapMessage#250

Merged
carterkozak merged 1 commit intoapache:masterfrom
travisspencer:master
Jan 14, 2019
Merged

LOG4J2-2530 Generalize check for MapMessage#250
carterkozak merged 1 commit intoapache:masterfrom
travisspencer:master

Conversation

@travisspencer
Copy link
Copy Markdown
Contributor

This fixes LOG4J2-2530 by generalizing the check for MapMessage to catch not only StringMapMessage objects but also StructuredMapMessgage objects, fixing an accidental breaking change introduced in 76aff58.

msg = (StringMapMessage) event.getMessage();
MapMessage msg;
if (event.getMessage() instanceof MapMessage) {
msg = (MapMessage) event.getMessage();
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.

Unfortunately this doesn't quite work because we cannot rely on casting map values to strings on line 82

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just remove the cast?

public String lookup(final LogEvent event, final String key) {
final Message msg = event.getMessage();
if (msg instanceof StringMapMessage) {
if (msg instanceof MapMessage) {
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.

Appending Object values to the stringbuilder on 69 is potentially dangerous, MapMessage.get(String) works around this by taking advantage of ParameterFormatter.deepToString.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added

@carterkozak
Copy link
Copy Markdown
Contributor

Would you mind adding tests to make sure we don't reintroduce this regression? The implementation looks great :-)

@travisspencer
Copy link
Copy Markdown
Contributor Author

travisspencer commented Jan 10, 2019 via email

…ssage are logged as well as StringMapMessage and ohter subtypes
@travisspencer
Copy link
Copy Markdown
Contributor Author

  • Tests added
  • Paperwork sent in
  • CI server is green
  • Commits are squashed

This PR can be merged and the issue can be closed, as far as I'm concerned.

If there's something that needs to be done further on my part, please let me know.

@carterkozak carterkozak merged commit 2c6d732 into apache:master Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants