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

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

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

ASF GitHub Bot logged work on LOG4J2-2564:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/May/19 03:44
            Start Date: 14/May/19 03:44
    Worklog Time Spent: 10m 
      Work Description: carterkozak commented on pull request #268: LOG4J2-2564: PatternParser chooses newInstance methods with known parameters
URL: https://github.com/apache/logging-log4j2/pull/268
 
 
   Fixes MapPatternConverter, which contains two newInstance methods where
   only one can be created using the PatternParser factory.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

            Worklog Id:     (was: 241482)
            Time Spent: 10m
    Remaining Estimate: 0h

> 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)