You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/07/06 10:07:43 UTC

[GitHub] [flink] zentol commented on a diff in pull request #20158: [FLINK-28357][datastream] Disallow null elements in StreamNode#typeSerializersIn

zentol commented on code in PR #20158:
URL: https://github.com/apache/flink/pull/20158#discussion_r914661704


##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamNode.java:
##########
@@ -265,17 +266,19 @@ public void setOperatorDescription(String operatorDescription) {
 
     public void setSerializersIn(TypeSerializer<?>... typeSerializersIn) {
         checkArgument(typeSerializersIn.length > 0);
-        this.typeSerializersIn = typeSerializersIn;
+        // Unfortunately code above assumes type serializer can be null, while users of for example
+        // getTypeSerializersIn would be confused by returning an array size of two with all
+        // elements set to null...
+        this.typeSerializersIn =
+                Arrays.stream(typeSerializersIn)
+                        .filter(typeSerializer -> typeSerializer != null)
+                        .toArray(TypeSerializer<?>[]::new);
     }
 
     public TypeSerializer<?>[] getTypeSerializersIn() {

Review Comment:
   Does the code calling this method make no assumptions about the indices?
   Let's say the original list of serializers contained 2 elements, with the first one being nul
   l.
   How does the code accessing this array figure out that what is now at index 0 is what it requires?



##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamNode.java:
##########
@@ -265,17 +266,19 @@ public void setOperatorDescription(String operatorDescription) {
 
     public void setSerializersIn(TypeSerializer<?>... typeSerializersIn) {
         checkArgument(typeSerializersIn.length > 0);
-        this.typeSerializersIn = typeSerializersIn;
+        // Unfortunately code above assumes type serializer can be null, while users of for example
+        // getTypeSerializersIn would be confused by returning an array size of two with all
+        // elements set to null...
+        this.typeSerializersIn =
+                Arrays.stream(typeSerializersIn)
+                        .filter(typeSerializer -> typeSerializer != null)
+                        .toArray(TypeSerializer<?>[]::new);
     }
 
     public TypeSerializer<?>[] getTypeSerializersIn() {

Review Comment:
   Does the code calling this method make no assumptions about the indices?
   Let's say the original list of serializers contained 2 elements, with the first one being null.
   How does the code accessing this array figure out that what is now at index 0 is what it requires?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org