mjsax commented on code in PR #10747:
URL: https://github.com/apache/kafka/pull/10747#discussion_r1093813869


##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/ChangedSerializer.java:
##########
@@ -46,33 +45,40 @@ public void setIfUnset(final SerdeGetter getter) {
     }
 
     /**
-     * @throws StreamsException if both old and new values of data are null, 
or if
-     * both values are not null
+     * @throws StreamsException if both old and new values of data are null.
      */
     @Override
     public byte[] serialize(final String topic, final Headers headers, final 
Change<T> data) {
-        final byte[] serializedKey;
-
-        // only one of the old / new values would be not null
-        if (data.newValue != null) {
-            if (data.oldValue != null) {
-                throw new StreamsException("Both old and new values are not 
null (" + data.oldValue
-                    + " : " + data.newValue + ") in ChangeSerializer, which is 
not allowed.");
-            }
-
-            serializedKey = inner.serialize(topic, headers, data.newValue);
+        final boolean oldValueIsNull = data.oldValue == null;
+        final boolean newValueIsNull = data.newValue == null;
+
+        final byte[] newData = inner.serialize(topic, headers, data.newValue);
+        final byte[] oldData = inner.serialize(topic, headers, data.oldValue);
+
+        final int newDataLength = newValueIsNull ? 0 : newData.length;
+        final int oldDataLength = oldValueIsNull ? 0 : oldData.length;

Review Comment:
   The implicit contract is, that `inner.serialize` can only return `null` if 
`data.oldValue` is `null`. Otherwise, the serializer has a bug. Hence, we 
should never hit a NPE here (or accept to hit it, to surface the bug in the 
serializer)



-- 
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: jira-unsubscr...@kafka.apache.org

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

Reply via email to