Details
-
Improvement
-
Resolution: Unresolved
-
Minor
-
1.0.13
-
None
-
None
Description
When using MDC and thread pools, code usually follows this pattern:
final Map context = MDC.getCopyOfContextMap(); executor.submit(new Runnable() { @Override public void run() { MDC.setContextMap(context); }
But if no MDC variables are set, getCopyOfContextMap() returns null and setContextMap then blows up. LogbackMDCAdapter.setContextMap uses Map.putAll which doesn't accept null. Therefore, one has to wrap the call to setContextMap in an annoying null check.
I suggest that setContextMap should handle a null argument gracefully by returning early. Alternatively, return Collections.emptyMap() or similar from getCopyOfContextMap.
Attachments
Issue Links
- relates to (out)
-
SLF4J-414 MDCAdapter does not handle null map
- Resolved