You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Marcono1234 (Jira)" <ji...@apache.org> on 2020/10/18 21:09:00 UTC

[jira] [Created] (LOG4J2-2948) Use IdentityHashMap for ParameterFormatter deja vu

Marcono1234 created LOG4J2-2948:
-----------------------------------

             Summary: Use IdentityHashMap for ParameterFormatter deja vu
                 Key: LOG4J2-2948
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2948
             Project: Log4j 2
          Issue Type: Improvement
            Reporter: Marcono1234


{{org.apache.logging.log4j.message.ParameterFormatter}} currently uses its {{identityToString(Object)}} method to create identifier strings for detecting recursive objects.

However, as noted by the description of that method, this approach is not completely foolproof:
{code}
     * As much as is reasonably practical, the hashCode method defined by
     * class {@code Object} does return distinct integers for distinct
     * objects. (This is typically implemented by converting the internal
     * address of the object into an integer, but this implementation
     * technique is not required by the Java&#8482; programming language.)
{code}

Would it make sense to switch to JDK's [{{java.util.IdentityHashMap}}|https://docs.oracle.com/javase/8/docs/api/java/util/IdentityHashMap.html] (converted to {{Set}} using {{Collections.newSetFromMap}})? I would assume, but have not tested it, that performance will also be better because it simply tests for equality by checking for reference equality whereas the current approach needs to compare strings.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)