Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-9694

Potentially NPE in CompositeTypeSerializerConfigSnapshot constructor

    XMLWordPrintableJSON

Details

    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. 

      Attachments

        Activity

          People

            pnowojski Piotr Nowojski
            yanghua vinoyang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: