You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Bhavesh Patel (JIRA)" <ji...@apache.org> on 2018/09/26 21:48:00 UTC

[jira] [Updated] (LOG4J2-2455) ResourceBundleLookup does not work with default values

     [ https://issues.apache.org/jira/browse/LOG4J2-2455?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bhavesh Patel updated LOG4J2-2455:
----------------------------------
    Description: 
ResourceBundleLookup for Log4j 2 work incorrectly with default values. If you do a lookup using the following

 
{code:java}
${bundle:application:application.name}{code}
 

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
{code:java}
${bundle:application:application.name:-None}{code}
 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.

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

 
{code:java}
${bundle:application:application.name}{code}
 

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
{code:java}
${bundle:application:application.name:-None}{code}
 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.


> ResourceBundleLookup does not work with default values
> ------------------------------------------------------
>
>                 Key: LOG4J2-2455
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2455
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Lookups
>    Affects Versions: 2.11.1
>            Reporter: Bhavesh Patel
>            Priority: Minor
>
> ResourceBundleLookup for Log4j 2 work incorrectly with default values. If you do a lookup using the following
>  
> {code:java}
> ${bundle:application:application.name}{code}
>  
> 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
> {code:java}
> ${bundle:application:application.name:-None}{code}
>  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.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)