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

Use IdentityHashMap for ParameterFormatter deja vu

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 2.14.1
    • None
    • None

    Description

      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:

           * 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™ programming language.)
      

      Would it make sense to switch to JDK's java.util.IdentityHashMap (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.

      Attachments

        Issue Links

          Activity

            People

              vy Volkan Yazici
              Marcono1234 Marcono1234
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: