Repository: kafka Updated Branches: refs/heads/trunk 21c6cfe50 -> a19729fe6
MINOR: Fixes version lookup exception. Given a schema with 2 versions (0 and 1), if you pass in a version of `2` you will get an `OutOfBoundsException` instead of an `IllegalArgumentException`. This fixes the problem by changing the check from `>` to `>=`, which will now return true in the given scenario. Author: Micah Zoltu <[email protected]> Reviewers: Ismael Juma <[email protected]>, Grant Henke <[email protected]>, Ewen Cheslack-Postava <[email protected]> Closes #748 from Zoltu/patch-1 Project: http://git-wip-us.apache.org/repos/asf/kafka/repo Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/a19729fe Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/a19729fe Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/a19729fe Branch: refs/heads/trunk Commit: a19729fe61b23178c6f91135cb81901f76f982f0 Parents: 21c6cfe Author: Micah Zoltu <[email protected]> Authored: Fri Jan 22 14:18:30 2016 -0800 Committer: Ewen Cheslack-Postava <[email protected]> Committed: Fri Jan 22 14:18:30 2016 -0800 ---------------------------------------------------------------------- .../kafka/common/protocol/ProtoUtils.java | 2 +- .../kafka/common/protocol/ProtoUtilsTest.java | 26 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kafka/blob/a19729fe/clients/src/main/java/org/apache/kafka/common/protocol/ProtoUtils.java ---------------------------------------------------------------------- diff --git a/clients/src/main/java/org/apache/kafka/common/protocol/ProtoUtils.java b/clients/src/main/java/org/apache/kafka/common/protocol/ProtoUtils.java index 9f38737..98befdc 100644 --- a/clients/src/main/java/org/apache/kafka/common/protocol/ProtoUtils.java +++ b/clients/src/main/java/org/apache/kafka/common/protocol/ProtoUtils.java @@ -27,7 +27,7 @@ public class ProtoUtils { if (apiKey < 0 || apiKey > schemas.length) throw new IllegalArgumentException("Invalid api key: " + apiKey); Schema[] versions = schemas[apiKey]; - if (version < 0 || version > versions.length) + if (version < 0 || version > latestVersion(apiKey)) throw new IllegalArgumentException("Invalid version for API key " + apiKey + ": " + version); if (versions[version] == null) throw new IllegalArgumentException("Unsupported version for API key " + apiKey + ": " + version); http://git-wip-us.apache.org/repos/asf/kafka/blob/a19729fe/clients/src/test/java/org/apache/kafka/common/protocol/ProtoUtilsTest.java ---------------------------------------------------------------------- diff --git a/clients/src/test/java/org/apache/kafka/common/protocol/ProtoUtilsTest.java b/clients/src/test/java/org/apache/kafka/common/protocol/ProtoUtilsTest.java new file mode 100644 index 0000000..440ca49 --- /dev/null +++ b/clients/src/test/java/org/apache/kafka/common/protocol/ProtoUtilsTest.java @@ -0,0 +1,26 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.common.protocol; + +import org.junit.Test; + +public class ProtoUtilsTest { + @Test(expected = IllegalArgumentException.class) + public void schemaVersionOutOfRange() { + ProtoUtils.requestSchema(ApiKeys.PRODUCE.id, Protocol.REQUESTS[ApiKeys.PRODUCE.id].length); + } +}
