记录一个序列化报空指针的问题 Caused by: com.esotericsoftware.kryo.KryoException: java.lang.NullPointerException

文章目录

  • 前言
  • 一、异常
  • 二、方案


前言

今天早上处理了一个序列化报空指针的问题,最终看了源码,也没找到对应空的地方。最后只好选择不做序列化处理。使用了transient 关键字


一、异常

Caused by: com.esotericsoftware.kryo.KryoException: java.lang.NullPointerException
Serialization trace:
exp (com.ai.gaimops.log.jsonobj.eventtypesource.SystemMapping)
systemMapping (com.ai.cass.dc.risk.domain.dto.eventType.EngineOriginalEventType)
	at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:82)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:495)
	at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:523)
	at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:61)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:495)
	at com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:599)
	at com.esotericsoftware.kryo.serializers.MapSerializer.write(MapSerializer.java:95)
	at com.esotericsoftware.kryo.serializers.MapSerializer.write(MapSerializer.java:21)
	at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:505)
	at org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer.copy(KryoSerializer.java:266)
	at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.pushToOperator(CopyingChainingOutput.java:80)
	at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.collect(CopyingChainingOutput.java:57)
	at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.collect(CopyingChainingOutput.java:29)
	at org.apache.flink.streaming.runtime.tasks.BroadcastingOutputCollector.collect(BroadcastingOutputCollector.java:77)
	at org.apache.flink.streaming.runtime.tasks.BroadcastingOutputCollector.collect(BroadcastingOutputCollector.java:32)
	at org.apache.flink.streaming.api.operators.CountingOutput.collect(CountingOutput.java:56)
	at org.apache.flink.streaming.api.operators.CountingOutput.collect(CountingOutput.java:29)
	at org.apache.flink.streaming.api.operators.TimestampedCollector.collect(TimestampedCollector.java:51)
	at com.ai.cass.dc.risk.domain.function.AioLogRichParamMapFunction.flatMap(AioLogRichParamMapFunction.java:123)
	at com.ai.cass.dc.risk.domain.function.AioLogRichParamMapFunction.flatMap(AioLogRichParamMapFunction.java:45)

二、方案

查看报错,可以快速定位到,实在序列化 EngineOriginalEventType 中的 SystemMapping 中的 exp 出的问题。
于是看了下SystemMapping

public class SystemMapping {

    private Boolean isMapping;

    private String targetField;

    private String systemField;

    private Boolean isExpression;

    private String expression;

    private Expression exp;
}
那就debug一下吧,报错的地方,找到序列化

记录一个序列化报空指针的问题 Caused by: com.esotericsoftware.kryo.KryoException: java.lang.NullPointerException_第1张图片
最终就是这里面空了个什么,导致的异常。我懒得找了。我选择直接避开。

    private transient  Expression exp;

ok,这样问题就搞定了。

你可能感兴趣的:(java,开发语言)