Fokko commented on a change in pull request #7487: [FLINK-11321] Clarify NPE on 
fetching nonexistent topic
URL: https://github.com/apache/flink/pull/7487#discussion_r247835274
 
 

 ##########
 File path: 
flink-connectors/flink-connector-kafka-0.9/src/main/java/org/apache/flink/streaming/connectors/kafka/internal/Kafka09PartitionDiscoverer.java
 ##########
 @@ -69,12 +69,18 @@ protected void initializeConnections() {
        }
 
        @Override
-       protected List<KafkaTopicPartition> 
getAllPartitionsForTopics(List<String> topics) throws WakeupException {
+       protected List<KafkaTopicPartition> 
getAllPartitionsForTopics(List<String> topics) throws WakeupException, 
IllegalArgumentException {
                List<KafkaTopicPartition> partitions = new LinkedList<>();
 
                try {
                        for (String topic : topics) {
-                               for (PartitionInfo partitionInfo : 
kafkaConsumer.partitionsFor(topic)) {
+                               List<PartitionInfo> partitions = 
kafkaConsumer.partitionsFor(topic);
+
+                               if (partitions == null) {
+                                       throw new 
IllegalArgumentException("Could not fetch partitions for Topic: 
%s".format(topic));
 
 Review comment:
   I've changed it to a RuntimeException. My initial thought was to throw an 
IllegalArgumentException because the supplied topic didn't exist. I want to 
fail if one of the topics couldn't be retrieved, otherwise, it might fail 
silently. Also, this doesn't change the existing behavior. Let me know what you 
think.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to