@@ -228,10 +228,10 @@ public Integer getPriority() {
228228 * @since 2.24.0
229229 */
230230 public LoggerContextFactory getLoggerContextFactory () {
231- final Class <?> implementation = loadLoggerContextFactory ();
231+ final Class <? extends LoggerContextFactory > implementation = loadLoggerContextFactory ();
232232 if (implementation != null ) {
233233 try {
234- return LoaderUtil .newInstanceOf (implementation . asSubclass ( LoggerContextFactory . class ) );
234+ return LoaderUtil .newInstanceOf (implementation );
235235 } catch (final ReflectiveOperationException e ) {
236236 LOGGER .error ("Failed to instantiate logger context factory {}." , implementation .getName (), e );
237237 }
@@ -259,13 +259,11 @@ public LoggerContextFactory getLoggerContextFactory() {
259259 if (threadContextMapClass != null ) {
260260 return threadContextMapClass ;
261261 }
262- if (threadContextMap == null ) {
263- return null ;
264- }
262+ final String threadContextMap = getThreadContextMap ();
265263 final ClassLoader loader = classLoader .get ();
266264 // Support for deprecated {@code META-INF/log4j-provider.properties} format.
267265 // In the remaining cases {@code loader == null}.
268- if (loader == null ) {
266+ if (loader == null || threadContextMap == null ) {
269267 return null ;
270268 }
271269 try {
@@ -276,7 +274,7 @@ public LoggerContextFactory getLoggerContextFactory() {
276274 LOGGER .error (
277275 "Class {} specified in {} does not extend {}" ,
278276 threadContextMap ,
279- url ,
277+ getUrl () ,
280278 ThreadContextMap .class .getName ());
281279 }
282280 } catch (final Exception e ) {
@@ -290,6 +288,14 @@ public LoggerContextFactory getLoggerContextFactory() {
290288 * @since 2.24.0
291289 */
292290 public ThreadContextMap getThreadContextMapInstance () {
291+ final Class <? extends ThreadContextMap > implementation = loadThreadContextMap ();
292+ if (implementation != null ) {
293+ try {
294+ return LoaderUtil .newInstanceOf (implementation );
295+ } catch (final ReflectiveOperationException e ) {
296+ LOGGER .error ("Failed to instantiate logger context factory {}." , implementation .getName (), e );
297+ }
298+ }
293299 final PropertiesUtil props = PropertiesUtil .getProperties ();
294300 return props .getBooleanProperty (DISABLE_CONTEXT_MAP ) || props .getBooleanProperty (DISABLE_THREAD_CONTEXT )
295301 ? NoOpThreadContextMap .INSTANCE
0 commit comments