qos-ch / logback

The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
Other
3k stars 1.28k forks source link

Getting a NullPointerException #870

Open sjmuir opened 18 hours ago

sjmuir commented 18 hours ago

I checked this in versions 1.3.14 and 1.5.10. In ch.qos.logback.classic.spi.LoggingEvent.getMDCPropertyMap(), I found this line:

MDCAdapter mdcAdapter = this.loggerContext.getMDCAdapter();

In some cases, I found that this returned null. This is not checked for, giving a NullPointerException on this line:

this.mdcPropertyMap = mdcAdapter.getCopyOfContextMap();

Please add a null pointer check.

ceki commented 18 hours ago

@sjmuir The mdcAdapter to loggerContext is assigned when Logback is initialized by LogbackServiceProvider.

Are you using a loggerContext created in a unit test or are you initializing Logback on your own?

sjmuir commented 17 hours ago

@ceki It's not a unit test, it's production code that we're trying to upgrade various libraries in, including logback.

This method is invoked by ch.qos.logback.classic.callAppenders(ILoggingEvent event). In my case, for this parameter:

event.toString() = "Logger[com.bluepumpkin.IU.FrameWork.FusionExchangeServer]" event.parent.toString() = "Logger[com.bluepumpkin.IU.FrameWork]" event.parent.parent.toString() = "Logger[com.bluepumpkin.IU]" event.parent.parent.parent.toString() = "Logger[com.bluepumpkin]" event.parent.parent.parent.parent.toString() = "Logger[com]" event.parent.parent.parent.parent.parent.toString() = "Logger[ROOT]" event.parent.parent.parent.parent.parent.parent = null

It's during the processing of "Logger[ROOT]" that the NullPointerException occurs.

ceki commented 17 hours ago

@ceki Normally, the mdcAdapter of loggerContext is set at logback initialization time. The issue of unset mdcAdapter is known to happen in case some component of your application initializes logback independently. This is not a logback issue but an issue of some other component of your application. Are you perhaps using an old version of spring-boot?