Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2522

Make MapMessageLookup.lookup usable with MapMessage again

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0.0, 2.11.2
    • Component/s: Core
    • Labels:
      None

      Description

      https://issues.apache.org/jira/browse/LOG4J2-1935
      changed MapMessage to a generic superclass,
      but decided to cast to StringMapMessage (a subclass with previous semantics) in MapMessageLookup.lookup

      Test case:

      {{ @Test}}
      {{ public void testEventMapMessage() {}}
          final HashMap<String, String> map = new HashMap<>();
          map.put("A", "B");
          final HashMap<String, String> eventMap = new HashMap<>();
          eventMap.put("A1", "B1");
          final StringMapMessage message = new StringMapMessage(eventMap);
          final LogEvent event = Log4jLogEvent.newBuilder()
              .setMessage(message)
              .build();
          final MapLookup lookup = new MapLookup(map);
          assertEquals("B", lookup.lookup(event, "A"));
          assertEquals("B1", lookup.lookup(event, "A1"));
      {{ }}}

      passes, but new test

      {{ @Test}}
      {{ public void testEventMapMessageNew() {}}
          final HashMap<String, String> map = new HashMap<>();
          map.put("A", "B");
          final HashMap<String, String> eventMap = new HashMap<>();
          eventMap.put("A1", 11);
          final MapMessage message = new MapMessage<>(eventMap);
          final LogEvent event = Log4jLogEvent.newBuilder()
              .setMessage(message)
              .build();
          final MapLookup lookup = new MapLookup(map);
          assertEquals("B", lookup.lookup(event, "A"));
          assertEquals("11", lookup.lookup(event, "A1"));
      {{ }}}

      Even worse, if we initialize MapMessage with a Map<String, String>, the test case still fails.

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ckozak Carter Kozak
                Reporter:
                lesiak Adam Lesiak
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m