You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ew...@apache.org on 2016/01/22 23:18:44 UTC
kafka git commit: MINOR: Fixes version lookup exception.
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 <mi...@zoltu.net>
Reviewers: Ismael Juma <is...@juma.me.uk>, Grant Henke <gr...@gmail.com>, Ewen Cheslack-Postava <ew...@confluent.io>
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 <mi...@zoltu.net>
Authored: Fri Jan 22 14:18:30 2016 -0800
Committer: Ewen Cheslack-Postava <me...@ewencp.org>
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);
+ }
+}