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

Plugins can cause ConverterKeys collisions with unpredictable results

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.1
    • Component/s: Plugins
    • Labels:
      None

      Description

      If I create a Converter plugin with ConverterKeys of "d" or "m" then there will be a collision with the built-in DatePatternConverter or MessagePatternConverter.

      It is unpredictable which plugin gets used.

      I see two resolutions:
      (1) detect collisions in PatternParser and emit a warning so we know which implementation will be used
      (2) use whichever Log4j2Plugins.dat appeared first in the CLASSPATH

      Predictable iteration order is usually accomplished by replacing HashMaps with LinkedHashMaps. Could easily do this for thie PluginManager.plugins field. But PluginRegistry uses a ConcurrentHashMap.

      Is there a good reason to use ConcurrentHashMaps in PluginRegistry? It doesn't really give you any concurrency – a caller to PluginManager.getPlugins could see a partially-loaded map if collectPlugins was still running. Why not synchronize collectPlugins and/or loadPlugins, and force any concurrent caller to getPlugins to wait until the loading was complete.

      I would give it a stab but I see other more important changes are probably underway for LOG4J2-741 and LOG4J2-673 and this can probably wait.

        Attachments

        1. Safer_PluginManager.patch
          56 kB
          Matt Sicker
        2. LOG4J2-745-patch-r1617171.txt
          53 kB
          Scott Harrington

          Issue Links

            Activity

              People

              • Assignee:
                jvz Matt Sicker
                Reporter:
                seh4nc Scott Harrington
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: