[ 
https://issues.apache.org/jira/browse/LOG4J2-2564?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16839055#comment-16839055
 ] 

Carter Kozak commented on LOG4J2-2564:
--------------------------------------

Potential fix, with a test that fails on master: 
[https://github.com/apache/logging-log4j2/pull/268]

It's unfortunate that there's no way to configure the map format from a 
pattern, that would be better than the second newInstance factory.

> Error using %K in pattern : MapPatternConverter cannot contain multiple 
> static newInstance method
> -------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-2564
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2564
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.11.2
>            Reporter: Anthony Communier
>            Assignee: Carter Kozak
>            Priority: Blocker
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> When using a %K in a pattern, the MapPatterConverter is used and there is an 
> error message :
> ERROR Class class org.apache.logging.log4j.core.pattern.MapPatternConverter 
> cannot contain multiple static newInstance methods
>  
> The control is done by 
> org.apache.logging.log4j.core.pattern.PatternParser.createConverter here :
> {{ _// Work around the regression bug in Class.getDeclaredMethods() in Oracle 
> Java in version > 1.6.0_17:_}}
> {{        _// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6815786_}}
> {{        _final Method[] methods = converterClass.getDeclaredMethods();_}}
> {{        _Method newInstanceMethod = null;_}}
> {{        _for (final Method method : methods) {_}}
> {{            _if (Modifier.isStatic(method.getModifiers()) && 
> method.getDeclaringClass().equals(converterClass)_}}
> {{                    _&& method.getName().equals("newInstance")) {_}}
> {{                _if (newInstanceMethod == null) {_}}
> {{                    _newInstanceMethod = method;_}}
> {{                _} else if 
> (method.getReturnType().equals(newInstanceMethod.getReturnType())) {_}}
> {{                    _LOGGER.error("Class " + converterClass + " cannot 
> contain multiple static newInstance methods");_}}
> {{                    _return null;_}}
> {{                _}_}}
> {{            _}_}}
> {{        _}_}}
>  
> The class org.apache.logging.log4j.core.pattern.MapPatternConverter contains 
> 2 *newInstances* message (teh second introduced in 2.11.2)
>  
>  _/**_
>      _* Obtains an instance of \{@link MapPatternConverter}._
>      _*_
>      _* @param options options, may be null or first element contains name of 
> property to format._
>      _* @return instance of \{@link MapPatternConverter}._
>      _*/_
>     _public static MapPatternConverter newInstance(final String[] options) {_
>         _return new MapPatternConverter(options, JAVA_UNQUOTED);_
>     _}_
> {color:#d04437}    _/**_{color}
> {color:#d04437}     _* Obtain an instance of \{@link 
> MapPatternConverter}._{color}
> {color:#d04437}     _*_{color}
> {color:#d04437}     _* @param options options, may be null or first element 
> contains name of property to format._{color}
> {color:#d04437}     _* @param format the format to use if no options are 
> given (i.e., options is null). Ignored if options is non-null._{color}
> {color:#d04437}     _* @return instance of \{@link 
> MapPatternConverter}._{color}
> {color:#d04437}     _* @since 2.11.2_{color}
> {color:#d04437}     _*/_{color}
> {color:#d04437}    _public static MapPatternConverter newInstance(final 
> String[] options, final MapFormat format) {_{color}
> {color:#d04437}        _return new MapPatternConverter(options, 
> Objects.toString(format, JAVA_UNQUOTED));_{color}
> {color:#d04437}    _}_{color}
>  
>  



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

Reply via email to