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



##########
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:
       I interpreted @stanislavkozlovski 's suggestion as being something like 
this:
   ```
             if (!(e.getCause.isInstanceOf[TopicExistsException] && 
topic.ifTopicDoesntExist()))
               throw e.getCause
   ```
   So you wouldn't need to return out of the method in this case.
   
   I do think that using AND here as suggested would be more intuitive.  The 
reason is because it's basically a special case we're handling here: we got 
TopicExistsException AND we had `--if-not-exists`.  Using the OR construct just 
feels unintuitive since we're basically taking the disjunction of the special 
case (enumerating all the ways we could not be in the special case.)
   
   Anyway, I don't feel that strongly about it.  If you really want to keep it 
as is, that's OK.




----------------------------------------------------------------
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