Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
2.9.1, 2.11.1
-
None
Description
It seems that when I want to extend LogPatternConverter, you quickly get an IllegalAccessException. The source of that problem seems to be the method PatternParser.finalizeConverter().
On one hand I should be able to create the static newInstance method in my newly created class (variable "newInstanceMethod"). Otherwise the method is not assigned:
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; } } }
On the other hand, "newInstanceMethod.invoke" is called without calling newInstanceMethod.setAccessible(true)
final Object newObj = newInstanceMethod.invoke(null, parms);
But your extended class would normally be ourside the package of PatternParser. Triggering an IllegalAccessException.
A possible workaround is to put your new class in the package org.apache.logging.log4j.core.pattern yourself. But that is not how we normally extend classes .