kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject kafka git commit: MINOR: Fix NPE handling unknown APIs in NodeApiVersions.toString
Date Tue, 21 Feb 2017 13:52:23 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk e41e78200 -> 3b8b7a4be


MINOR: Fix NPE handling unknown APIs in NodeApiVersions.toString

Author: Jason Gustafson <jason@confluent.io>

Reviewers: Colin P. Mccabe <cmccabe@confluent.io>, Ismael Juma <ismael@juma.me.uk>

Closes #2561 from hachikuji/fix-npe-api-version-tostring


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/3b8b7a4b
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/3b8b7a4b
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/3b8b7a4b

Branch: refs/heads/trunk
Commit: 3b8b7a4be39cb4a3f7257f8a17f74a887572e627
Parents: e41e782
Author: Jason Gustafson <jason@confluent.io>
Authored: Tue Feb 21 13:52:18 2017 +0000
Committer: Ismael Juma <ismael@juma.me.uk>
Committed: Tue Feb 21 13:52:18 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/kafka/clients/NodeApiVersions.java   | 11 +++++------
 .../org/apache/kafka/clients/NodeApiVersionsTest.java    |  8 ++++++++
 2 files changed, 13 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/3b8b7a4b/clients/src/main/java/org/apache/kafka/clients/NodeApiVersions.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/clients/NodeApiVersions.java b/clients/src/main/java/org/apache/kafka/clients/NodeApiVersions.java
index aa9c85a..906c226 100644
--- a/clients/src/main/java/org/apache/kafka/clients/NodeApiVersions.java
+++ b/clients/src/main/java/org/apache/kafka/clients/NodeApiVersions.java
@@ -31,7 +31,6 @@ import java.util.TreeMap;
  * An internal class which represents the API versions supported by a particular node.
  */
 public class NodeApiVersions {
-    private static final Short API_NOT_ON_NODE = null;
     private static final short NODE_TOO_OLD = (short) -1;
     private static final short NODE_TOO_NEW = (short) -2;
     private final Collection<ApiVersion> nodeApiVersions;
@@ -47,7 +46,7 @@ public class NodeApiVersions {
      * @return A new NodeApiVersions object.
      */
     public static NodeApiVersions create() {
-        return create(Collections.EMPTY_LIST);
+        return create(Collections.<ApiVersion>emptyList());
     }
 
     /**
@@ -98,7 +97,7 @@ public class NodeApiVersions {
      */
     public short usableVersion(ApiKeys apiKey) {
         Short usableVersion = usableVersions.get(apiKey);
-        if (usableVersion == API_NOT_ON_NODE)
+        if (usableVersion == null)
             throw new UnsupportedVersionException("The broker does not support " + apiKey);
         else if (usableVersion == NODE_TOO_OLD)
             throw new UnsupportedVersionException("The broker is too old to support " + apiKey
+
@@ -160,17 +159,17 @@ public class NodeApiVersions {
         ApiKeys apiKey = null;
         if (ApiKeys.hasId(apiVersion.apiKey)) {
             apiKey = ApiKeys.forId(apiVersion.apiKey);
-        }
-        if (apiKey != null) {
             bld.append(apiKey.name).append("(").append(apiKey.id).append("): ");
         } else {
-            bld.append("UNKNOWN(").append(apiKey.id).append("): ");
+            bld.append("UNKNOWN(").append(apiVersion.apiKey).append("): ");
         }
+
         if (apiVersion.minVersion == apiVersion.maxVersion) {
             bld.append(apiVersion.minVersion);
         } else {
             bld.append(apiVersion.minVersion).append(" to ").append(apiVersion.maxVersion);
         }
+
         if (apiKey != null) {
             Short usableVersion = usableVersions.get(apiKey);
             if (usableVersion == NODE_TOO_OLD)

http://git-wip-us.apache.org/repos/asf/kafka/blob/3b8b7a4b/clients/src/test/java/org/apache/kafka/clients/NodeApiVersionsTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/clients/NodeApiVersionsTest.java b/clients/src/test/java/org/apache/kafka/clients/NodeApiVersionsTest.java
index 8773d9c..53c47c8 100644
--- a/clients/src/test/java/org/apache/kafka/clients/NodeApiVersionsTest.java
+++ b/clients/src/test/java/org/apache/kafka/clients/NodeApiVersionsTest.java
@@ -30,6 +30,7 @@ import java.util.LinkedList;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class NodeApiVersionsTest {
 
@@ -48,6 +49,13 @@ public class NodeApiVersionsTest {
     }
 
     @Test
+    public void testUnknownApiVersionsToString() {
+        ApiVersion unknownApiVersion = new ApiVersion((short) 337, (short) 0, (short) 1);
+        NodeApiVersions versions = new NodeApiVersions(Collections.singleton(unknownApiVersion));
+        assertTrue(versions.toString().endsWith("UNKNOWN(337): 0 to 1)"));
+    }
+
+    @Test
     public void testVersionsToString() {
         List<ApiVersion> versionList = new ArrayList<>();
         for (ApiKeys apiKey : ApiKeys.values()) {


Mime
View raw message