kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject kafka git commit: KAFKA-3781; Errors.exceptionName() can throw NPE
Date Tue, 07 Jun 2016 03:29:03 GMT
Repository: kafka
Updated Branches:
  refs/heads/0.10.0 780bc646d -> b372c4bf4


KAFKA-3781; Errors.exceptionName() can throw NPE

Author: Ismael Juma <ismael@juma.me.uk>

Reviewers: Grant Henke <granthenke@gmail.com>, Ewen Cheslack-Postava <ewen@confluent.io>

Closes #1476 from ijuma/kafka-3781-exception-name-npe

(cherry picked from commit feab5a374a33a7b7b8e96c6a88b872c4db33dcf1)
Signed-off-by: Ewen Cheslack-Postava <me@ewencp.org>


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

Branch: refs/heads/0.10.0
Commit: b372c4bf4a65c25086fc7d8e60f1970d5486ce74
Parents: 780bc64
Author: Ismael Juma <ismael@juma.me.uk>
Authored: Mon Jun 6 20:28:31 2016 -0700
Committer: Ewen Cheslack-Postava <me@ewencp.org>
Committed: Mon Jun 6 20:28:57 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/kafka/common/protocol/Errors.java     |  4 ++--
 .../java/org/apache/kafka/common/protocol/ErrorsTest.java | 10 ++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/b372c4bf/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java b/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java
index 64a709e..bd7310b 100644
--- a/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java
+++ b/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java
@@ -170,10 +170,10 @@ public enum Errors {
     }
 
     /**
-     * Returns the class name of the exception
+     * Returns the class name of the exception or null if this is {@code Errors.NONE}.
      */
     public String exceptionName() {
-        return exception.getClass().getName();
+        return exception == null ? null : exception.getClass().getName();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/kafka/blob/b372c4bf/clients/src/test/java/org/apache/kafka/common/protocol/ErrorsTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/common/protocol/ErrorsTest.java b/clients/src/test/java/org/apache/kafka/common/protocol/ErrorsTest.java
index 2d96e58..e198e73 100644
--- a/clients/src/test/java/org/apache/kafka/common/protocol/ErrorsTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/protocol/ErrorsTest.java
@@ -77,4 +77,14 @@ public class ErrorsTest {
         assertEquals("forException should default to unknown", Errors.UNKNOWN, error);
     }
 
+    @Test
+    public void testExceptionName() {
+        String exceptionName = Errors.UNKNOWN.exceptionName();
+        assertEquals("org.apache.kafka.common.errors.UnknownServerException", exceptionName);
+        exceptionName = Errors.NONE.exceptionName();
+        assertNull(exceptionName);
+        exceptionName = Errors.INVALID_TOPIC_EXCEPTION.exceptionName();
+        assertEquals("org.apache.kafka.common.errors.InvalidTopicException", exceptionName);
+    }
+
 }


Mime
View raw message