stanislavkozlovski commented on a change in pull request #8737:
URL: https://github.com/apache/kafka/pull/8737#discussion_r431953983



##########
File path: core/src/main/scala/kafka/admin/TopicCommand.scala
##########
@@ -247,8 +247,12 @@ object TopicCommand extends Logging {
         val createResult = 
adminClient.createTopics(Collections.singleton(newTopic))
         createResult.all().get()
         println(s"Created topic ${topic.name}.")
-      } else {
-        throw new IllegalArgumentException(s"Topic ${topic.name} already 
exists")
+      } catch {
+        case e : ExecutionException =>
+          if (e.getCause == null)
+            throw e
+          if (!e.getCause.isInstanceOf[TopicExistsException] || 
!topic.ifTopicDoesntExist())

Review comment:
       nit: I had some trouble reading this, since it's two not operators with 
an OR statement. Would this be easier to read as `if 
e.getCause.isInstanceOf[TopicExistsException] && topic.ifTopicDoesntExist()` ? 
Note that [scala doesn't require a null check on the exception before calling 
isInstanceOf](https://stackoverflow.com/questions/14203201/does-scala-null-count-as-an-instance-of-another-type)
   
   I think it's more conventional in Scala to have full if/else branches rather 
than guard statements




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to