chia7712 commented on code in PR #23317:
URL: https://github.com/apache/kafka/pull/23317#discussion_r3990129042


##########
generator/src/main/java/org/apache/kafka/message/MessageSpec.java:
##########
@@ -109,6 +124,77 @@ public MessageSpec(@JsonProperty("name") String name,
         }
     }
 
+    /**
+     * Check that every header version exists, and that a flexible body maps 
to a flexible header.
+     * The bounds come from the header schemas passed in: {@code 
highestHeader} is the highest valid
+     * version of RequestHeader / ResponseHeader, and {@code 
firstFlexibleHeader} its first flexible
+     * version. ApiVersionsResponse is the exception and is pinned to header 
v0 (KIP-511). The rest of
+     * the invariant (that non-flexible bodies use the fixed non-flexible 
header) is enforced against
+     * the generated code by ApiMessageTypeTest.
+     *
+     * @param requestHeader  the RequestHeader schema, or null if it was not 
found in the same directory
+     * @param responseHeader the ResponseHeader schema, or null if it was not 
found in the same directory
+     */
+    void checkHeaderVersions(MessageSpec requestHeader, MessageSpec 
responseHeader) {
+        if (headerVersions.isEmpty()) {
+            return;
+        }
+        boolean isRequest = type == MessageSpecType.REQUEST;
+        String typeName = isRequest ? "request" : "response";
+        MessageSpec header = isRequest ? requestHeader : responseHeader;
+        if (header == null) {
+            throw new RuntimeException("Message " + name() + " specifies 
headerVersions, but no " +
+                (isRequest ? "RequestHeader" : "ResponseHeader") + " schema 
was found in the same directory; " +
+                "the header schema is needed to check which header versions 
exist.");
+        }
+        // The lower bound stays 0: the map covers retired body versions that 
used a header version
+        // below the header schema's own valid range (e.g. header v0 for 
ControlledShutdown v0).

Review Comment:
   `ControlledShutdown` was dropped in 4.0, so this reason seems a bit odd to 
me. Maybe we can just check the lower bound too



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to