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

Diego Villablanca updated LOG4J2-2850:
--------------------------------------
    Description: 
When I instantiate LocalizedMessageFactory with the String baseName constructor 
and then I create a new LocalizedMessage by the method _public Message 
newMessage(final String key)_, it instantiates the message with the constructor 
that use String messagePattern and String key, using the resource bundle 
baseName as messagePattern, and the key as an argument of the pattern.

@Override
 public Message newMessage(final String key) {
 if (resourceBundle == null) {
 return new LocalizedMessage(baseName, key);
 }
 return new LocalizedMessage(resourceBundle, key);
 }

 

The constructor of LocalizedMessage used is:

***public LocalizedMessage(final String messagePattern, final Object arg) {*
 *this((ResourceBundle) null, (Locale) null, messagePattern, new Object[] 
\{arg});*
 *}*

The Factory should use this constructor:

public LocalizedMessage(final String baseName, final String key, final Object 
arg) {
 this(baseName, (Locale) null, key, new Object[] \{arg});
 }

 

The fix should be:

@Override
 public Message newMessage(final String key) {
 if (resourceBundle == null) {
 return new LocalizedMessage(baseName, key, null);
 }
 return new LocalizedMessage(resourceBundle, key);
 }

 

  was:
When I instantiate LocalizedMessageFactory with the String baseName constructor 
and then I create a new LocalizedMessage by the method _public Message 
newMessage(final String key)_, it instantiates the message with the constructor 
that use String messagePattern and String key, using the resource bundle 
baseName as messagePattern, and the key as an argument of the pattern.

@Override
 public Message newMessage(final String key) {
    if (resourceBundle == null) {
        *return new LocalizedMessage(baseName, key);*
    }
    return new LocalizedMessage(resourceBundle, key);
 }

 

The constructor of LocalizedMessage used is:

*public LocalizedMessage(final String {color:#ff0000}messagePattern{color}, 
final Object {color:#ff0000}arg{color}) {*
      *this((ResourceBundle) null, (Locale) null, 
{color:#ff0000}messagePattern{color}, new Object[] 
{{color:#FF0000}arg{color}});*
 *}*

The Factory should use this constructor:

public LocalizedMessage(final String baseName, final String key, final Object 
arg)

{      this(baseName, (Locale) null, key, new Object[] 

{arg}

);
 }

The fix should be:

/**
 * @since 2.8
 */
 @Override
 public Message newMessage(final String key) {
      if (resourceBundle == null)
 Unknown macro:
Unknown macro: {         *return new LocalizedMessage(baseName, key, 
{color:#ff0000}null{color});*     }
     return new LocalizedMessage(resourceBundle, key);
 }


> LocalizedMessageFactory creates new message with baseName as messagePattern
> ---------------------------------------------------------------------------
>
>                 Key: LOG4J2-2850
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2850
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 2.13.3
>            Reporter: Diego Villablanca
>            Priority: Trivial
>              Labels: easyfix
>   Original Estimate: 10m
>  Remaining Estimate: 10m
>
> When I instantiate LocalizedMessageFactory with the String baseName 
> constructor and then I create a new LocalizedMessage by the method _public 
> Message newMessage(final String key)_, it instantiates the message with the 
> constructor that use String messagePattern and String key, using the resource 
> bundle baseName as messagePattern, and the key as an argument of the pattern.
> @Override
>  public Message newMessage(final String key) {
>  if (resourceBundle == null) {
>  return new LocalizedMessage(baseName, key);
>  }
>  return new LocalizedMessage(resourceBundle, key);
>  }
>  
> The constructor of LocalizedMessage used is:
> ***public LocalizedMessage(final String messagePattern, final Object arg) {*
>  *this((ResourceBundle) null, (Locale) null, messagePattern, new Object[] 
> \{arg});*
>  *}*
> The Factory should use this constructor:
> public LocalizedMessage(final String baseName, final String key, final Object 
> arg) {
>  this(baseName, (Locale) null, key, new Object[] \{arg});
>  }
>  
> The fix should be:
> @Override
>  public Message newMessage(final String key) {
>  if (resourceBundle == null) {
>  return new LocalizedMessage(baseName, key, null);
>  }
>  return new LocalizedMessage(resourceBundle, key);
>  }
>  



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

Reply via email to