任务启动时异常:java.lang.NullPointerException: null

问题描述/异常栈

java.lang.NullPointerException: null
    at java.lang.String.<init>(String.java:566) ~[?:1.8.0_152]
    at org.apache.flink.formats.json.JsonRowDataDeserializationSchema.deserialize(JsonRowDataDeserializationSchema.java:104) ~[plugin_ne-flink-1.12.4-1.1.1_scala2.12_hive2.1.1-3.8.0-1.2.2-SNAPSHOT.jar:?]
    at org.apache.flink.formats.json.JsonRowDataDeserializationSchema.deserialize(JsonRowDataDeserializationSchema.java:46) ~[plugin_ne-flink-1.12.4-1.1.1_scala2.12_hive2.1.1-3.8.0-1.2.2-SNAPSHOT.jar:?]
    at org.apache.flink.api.common.serialization.DeserializationSchema.deserialize(DeserializationSchema.java:82) ~[plugin_ne-flink-1.12.4-1.1.1_scala2.12_hive2.1.1-3.8.0-1.2.2-SNAPSHOT.jar:?]
    at org.apache.flink.streaming.connectors.kafka.table.DynamicKafkaDeserializationSchema.deserialize(DynamicKafkaDeserializationSchema.java:113) ~[plugin_ne-flink-1.12.4-1.1.1_scala2.12_hive2.1.1-3.8.0-1.2.2-SNAPSHOT.jar:?]
    at org.apache.flink.streaming.connectors.kafka.internals.KafkaFetcher.partitionConsumerRecordsHandler(KafkaFetcher.java:179) ~[plugin_ne-flink-1.12.4-1.1.1_scala2.12_hive2.1.1-3.8.0-1.2.2-SNAPSHOT.jar:?]
    at org.apache.flink.streaming.connectors.kafka.internals.KafkaFetcher.runFetchLoop(KafkaFetcher.java:142) ~[plugin_ne-flink-1.12.4-1.1.1_scala2.12_hive2.1.1-3.8.0-1.2.2-SNAPSHOT.jar:?]
    at org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumerBase.run(FlinkKafkaConsumerBase.java:826) ~[plugin_ne-flink-1.12.4-1.1.1_scala2.12_hive2.1.1-3.8.0-1.2.2-SNAPSHOT.jar:?]
    at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:110) ~[plugin_ne-flink-1.12.4-1.1.1_scala2.12_hive2.1.1-3.8.0-1.2.2-SNAPSHOT.jar:?]
    at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:66) ~[plugin_ne-flink-1.12.4-1.1.1_scala2.12_hive2.1.1-3.8.0-1.2.2-SNAPSHOT.jar:?]
    at org.apache.flink.streaming.runtime.tasks.SourceStreamTask$LegacySourceFunctionThread.run(SourceStreamTask.java:263) ~[plugin_ne-flink-1.12.4-1.1.1_scala2.12_hive2.1.1-3.8.0-1.2.2-SNAPSHOT.jar:?]

解决方案

Flink内核版本:1.12
添加参数:'json.fail-on-missing-field' = 'true'
当解析字段缺失时,是跳过当前字段或行,还是抛出错误失败(默认为 false,即抛出错误失败)。

问题原因

源端反序列化异常,多为有脏数据导致。

作者:邓崃翔