[ 
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 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);
 }

 


> 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