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

ResourceBundleLookup does not work with default values

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.11.1
    • Fix Version/s: None
    • Component/s: Lookups
    • Labels:
      None

      Description

      ResourceBundleLookup for Log4j 2 work incorrectly with default values. If you do a lookup using the following

      ${bundle:application:application.name}

      it would work fine and return the value for application.name, if present.

      But if you want to use a default value, incase if the key is not found, the lookup functions incorrectly. If you do a lookup using the following

      ${bundle:application:application.name:-None}

       the lookup should return "None" if the application key is not found. But this particular lookup will always return "None" even if the key is present in the specified resource bundle.

      The issue seems to be that the resolveVariable() in org.apache.logging.log4j.core.lookup.StrSubstitutor class returns null; as the resolver is not able to perform the lookup correctly. The issue tracks back to org.apache.logging.log4j.core.lookup.Interpolator class. The constructor

      Interpolator(final Map<String, String> properties) does not add ResourceBundleLookup to the "strLookupMap".

      The fix is to add the ResourceBundleLookup to this map and then the bundle lookup functions correctly with the default value. The test for this feature, ResourceBundleLookupTest.java, needs to be updated to test for this scenario.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              bhaveshhpatel Bhavesh Patel
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: