hachikuji commented on a change in pull request #9600: URL: https://github.com/apache/kafka/pull/9600#discussion_r555419244
########## File path: clients/src/main/java/org/apache/kafka/common/protocol/ApiVersion.java ########## @@ -53,4 +53,18 @@ public String toString() { ", maxVersion= " + maxVersion + ")"; } + + public static ApiVersion versionsInCommon(ApiKeys apiKey, ApiVersion supportedVersions, + short minAllowedVersion, short maxAllowedVersion) { + if (supportedVersions == null) + throw new UnsupportedVersionException("The broker does not support " + apiKey); + + short minVersion = (short) Math.max(minAllowedVersion, supportedVersions.minVersion); + short maxVersion = (short) Math.min(maxAllowedVersion, supportedVersions.maxVersion); + if (minVersion > maxVersion) + throw new UnsupportedVersionException("The broker does not support " + apiKey + Review comment: Not totally sure this gets thrown in the right place. If there are no overlapping versions, perhaps we should leave the api out of the result. Perhaps that suggests we should use this definition: ```java // Return common api versions or empty if there are none public Optional<ApiVersion> intersect(ApiVersion other); ``` Then we can let the caller decide how to handle this case. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org