Details
-
Bug
-
Status: Closed
-
Blocker
-
Resolution: Fixed
-
2.11.2
-
None
-
None
Description
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);
}
/**
* Obtain an instance of {@link MapPatternConverter}.
*
* @param options options, may be null or first element contains name of property to format.
* @param format the format to use if no options are given (i.e., options is null). Ignored if options is non-null.
* @return instance of {@link MapPatternConverter}.
* @since 2.11.2
*/
public static MapPatternConverter newInstance(final String[] options, final MapFormat format) {
return new MapPatternConverter(options, Objects.toString(format, JAVA_UNQUOTED));
}
Attachments
Issue Links
- links to