davidmoten / subethasmtp

SubEtha SMTP is a Java library for receiving SMTP mail

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MDC Context Null Pointer

charliem opened this issue · comments

Whenever a new Server session is initiated by an inbound email a Null Pointer Exception is thrown. What appears to be happening is the parentLoggingMdcContext is null. The app this is being integrated into uses Log4J via SL4J. However it doesn't use MDC. I don't see why the context is coming back null but it is. Below is the exception produced:

Exception in thread "pool-4-thread-1" java.lang.NullPointerException
at org.slf4j.impl.Log4jMDCAdapter.setContextMap(Log4jMDCAdapter.java:81)
at org.slf4j.MDC.setContextMap(MDC.java:246)
at org.subethamail.smtp.server.Session.run(Session.java:126)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:835)

I solved this locally by guarding the setContextMap call with a Null check on parentLoggingMdcContext.

I haven't looked at the code yet but what versions of slf4j dependencies are you using?

Looks like this bug report on slf4j

I've added this null check as you described and released in 5.1 on Maven Central.