Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.5.0
Description
the partial specific exception stack trace :
Caused by: java.lang.NullPointerException at org.apache.flink.api.common.typeutils.CompositeTypeSerializerConfigSnapshot.<init>(CompositeTypeSerializerConfigSnapshot.java:53) at org.apache.flink.table.runtime.types.CRowSerializer$CRowSerializerConfigSnapshot.<init>(CRowSerializer.scala:120) at org.apache.flink.table.runtime.types.CRowSerializer$CRowSerializerConfigSnapshot.<init>(CRowSerializer.scala:123) at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.Class.newInstance(Class.java:442) at org.apache.flink.util.InstantiationUtil.instantiate(InstantiationUtil.java:319) ... 20 more
related code is :
public CompositeTypeSerializerConfigSnapshot(TypeSerializer<?>... nestedSerializers) { Preconditions.checkNotNull(nestedSerializers); this.nestedSerializersAndConfigs = new ArrayList<>(nestedSerializers.length); for (TypeSerializer<?> nestedSerializer : nestedSerializers) { TypeSerializerConfigSnapshot configSnapshot = nestedSerializer.snapshotConfiguration(); this.nestedSerializersAndConfigs.add( new Tuple2<TypeSerializer<?>, TypeSerializerConfigSnapshot>( nestedSerializer.duplicate(), Preconditions.checkNotNull(configSnapshot))); } }
exception happens at :
TypeSerializerConfigSnapshot configSnapshot = nestedSerializer.snapshotConfiguration();
the reason is the type of constructor's parameter "..." used "varargs" feature. The initialize code in CRowSerializer.scala is :
def this() = this(null) // Scala code
when invoked this, actually the the type of CompositeTypeSerializerConfigSnapshot's
nestedSerializers parameter is :
TypeSerializer<?>[] nestedSerializers = new TypeSerializer<?>[] {null};
so the checkNotNull precondition statement :
Preconditions.checkNotNull(nestedSerializers);
is always useless.
So we should check the object reference in for loop to protect NPE.