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

Log4j 1.2 bridge throws a ClassCastException when logging a Map with non-String keys

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.13.0, 2.17.1
    • 2.17.2
    • Log4j 1.2 bridge
    • None
    • OS: Windows 10 Enterprise 64bit

      Java version: zulu8.31.0.1-jdk8.0.181-win_x64{}

    Description

      Our existing business logic contains a debug message which print out a org.apache.commons.collections.map.MultiKeyMap:

       

      MultiKeyMap prnMap = MultiKeyMap.decorate(new LinkedMap());
      prnMap.put("0", "1", "2");
      logger.debug(prnMap);
      

       

      in log4j-1.2-api 2.12.4, it can be print out properly:

       

      {MultiKey[0, 1]=2}

       

      However it becomes an ClassCastException since 2.13.0 (including the latest 2.17.1)

      Exception in thread "main" java.lang.ClassCastException: org.apache.commons.collections.keyvalue.MultiKey cannot be cast to java.lang.String
          at org.apache.logging.log4j.util.SortedArrayStringMap.<init>(SortedArrayStringMap.java:154)
          at org.apache.logging.log4j.message.MapMessage.<init>(MapMessage.java:125)
          at org.apache.log4j.Category.maybeLog(Category.java:507)
          at org.apache.log4j.Category.debug(Category.java:243)
          at sideproject.sideproject.App.proeces(App.java:25)
          at sideproject.sideproject.App.main(App.java:17)

      As the map can print out using System.out without issue, we are wondering if it is a bug in Apache Log4j 1.x Compatibility API

      A GitHub Project is prepared for reference: shin779/log4j-multikeymap (github.com)

      Attachments

        Issue Links

          Activity

            People

              ggregory Gary D. Gregory
              bcfsham Barry Sham
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: