You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Gary Gregory (JIRA)" <ji...@apache.org> on 2019/03/14 17:11:00 UTC

[jira] [Commented] (LOG4J2-2564) Error using %K in pattern : MapPatternConverter cannot contain multiple static newInstance method

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

Gary Gregory commented on LOG4J2-2564:
--------------------------------------

It seems we are missing a unit test to catch this case.

> 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
>            Priority: Blocker
>
> 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)