[ https://issues.apache.org/jira/browse/LOG4J2-3410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17495444#comment-17495444 ]
Piotr P. Karwasz commented on LOG4J2-3410: ------------------------------------------ To me it also seems like a bug in [{{Category#forcedLog}}|https://github.com/apache/logging-log4j2/blob/e0a53b06c67769b87f5bf3c67681cbd2fa5b1cd6/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java#L310] and [{{Category#maybeLog}}|https://github.com/apache/logging-log4j2/blob/e0a53b06c67769b87f5bf3c67681cbd2fa5b1cd6/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java#L561]: not all maps are String maps. This should probably be refactored into a special {{MessageFactory}} for Log4j 1.x bridge. I could write a PR tonight. > Log4j 1.x Compatibility API - ClassCastException when logging MultiKeyMap > ------------------------------------------------------------------------- > > Key: LOG4J2-3410 > URL: https://issues.apache.org/jira/browse/LOG4J2-3410 > Project: Log4j 2 > Issue Type: Bug > Components: Log4j 1.2 bridge > Affects Versions: 2.13.0, 2.17.1 > Environment: OS: Windows 10 Enterprise 64bit > Java version: zulu8.31.0.1-jdk8.0.181-win_x64{*}{*} > Reporter: Barry Sham > Priority: Major > > Our existing business logic contains a debug message which print out a > {_}org.apache.commons.collections.map.MultiKeyMap{_}: > > {code:java} > MultiKeyMap prnMap = MultiKeyMap.decorate(new LinkedMap()); > prnMap.put("0", "1", "2"); > logger.debug(prnMap); > {code} > > in {*}log4j-1.2-api 2.12.4{*}, it can be print out > {color:#4c9aff}properly{color}: > > {code:java} > {MultiKey[0, 1]=2}{code} > > However it becomes an {color:#FF0000}ClassCastException {color}+since > *2.13.0* (including the latest {*}2.17.1{*})+ > {code:java} > 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){code} > 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)|https://github.com/shin779/log4j-multikeymap] -- This message was sent by Atlassian Jira (v8.20.1#820001)