Browse Source

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
pull/1474/merge
Ismael Juma 9 years ago committed by Ewen Cheslack-Postava
parent
commit
feab5a374a
  1. 4
      clients/src/main/java/org/apache/kafka/common/protocol/Errors.java
  2. 10
      clients/src/test/java/org/apache/kafka/common/protocol/ErrorsTest.java

4
clients/src/main/java/org/apache/kafka/common/protocol/Errors.java

@ -170,10 +170,10 @@ public enum Errors { @@ -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();
}
/**

10
clients/src/test/java/org/apache/kafka/common/protocol/ErrorsTest.java

@ -77,4 +77,14 @@ public class ErrorsTest { @@ -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);
}
}

Loading…
Cancel
Save