You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flink.apache.org by "Szymon (Jira)" <ji...@apache.org> on 2024/09/05 08:49:00 UTC
[jira] [Created] (FLINK-36227) NullPointerException when starting flink with logback logger
Szymon created FLINK-36227:
------------------------------
Summary: NullPointerException when starting flink with logback logger
Key: FLINK-36227
URL: https://issues.apache.org/jira/browse/FLINK-36227
Project: Flink
Issue Type: Bug
Components: API / Core
Affects Versions: 1.20.0
Environment: The error rise when flink is staring with logback as logger
Reporter: Szymon
I think that there is a bug in flink code in class MdcUtils.
When I run job on standalone flink or unit test with MiniCluster I get below error. This error rise only when logback is used, as logging adapter. I use logback version 1.2.13 because in flink documentation [https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/deployment/advanced/logging/] is written “Logback 1.3+ requires SLF4J 2, which is currently not supported.”
_14:33:41.111 [flink-pekko.actor.default-dispatcher-5] INFO org.apache.flink.runtime.rpc.pekko.PekkoRpcActor - The RpcEndpoint taskmanager_0 failed._
_java.lang.NullPointerException: null_
_at java.base/java.util.HashMap.putMapEntries(HashMap.java:497)_
_at java.base/java.util.HashMap.putAll(HashMap.java:781)_
_at java.base/java.util.Collections$SynchronizedMap.putAll(Collections.java:2604)_
_at ch.qos.logback.classic.util.LogbackMDCAdapter.setContextMap(LogbackMDCAdapter.java:197)_
_at org.slf4j.MDC.setContextMap(MDC.java:264)_
_at org.apache.flink.util.MdcUtils.lambda$withContext$0(MdcUtils.java:48)_
I checked flink code and in my opinion there should be additional check in class MdcUtils in method
_public static MdcCloseable withContext(Map<String, String> context) {_
_final Map<String, String> orig = MDC.getCopyOfContextMap();_
_MDC.setContextMap(context);_
_return () -> MDC.setContextMap(orig);_
_}_
this method use MDC.getCopyOfContextMap();. Description of this method says that returned value may be null. So when variable orig is null and is passed to “MDC.setContextMap”. At the end this null is passed to class LogbackMDCAdapter to method setContextMap where this null Is passed to newMap.putAll(contextMap), and then NullPointerException rise. I checked this for logback 1.2.13 where setContextMap is
_public void setContextMap(Map<String, String> contextMap) {_
_lastOperation.set(WRITE_OPERATION);_
_Map<String, String> newMap = Collections.synchronizedMap(new HashMap<String, String>());_
_newMap.putAll(contextMap);_
_// the newMap replaces the old one for serialisation's sake_
_copyOnThreadLocal.set(newMap);_
_}_
This error should not appear when logback version is 1.3.3 or higher
_@SuppressWarnings("unchecked")_
_public void setContextMap(Map contextMap) {_
_if (contextMap != null) {_
_readWriteThreadLocalMap.set(new HashMap<String, String>(contextMap));_
_} else {_
_readWriteThreadLocalMap.set(null);_
_}_
_nullifyReadOnlyThreadLocalMap();_
_}_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)