dajac commented on code in PR #23505:
URL: https://github.com/apache/kafka/pull/23505#discussion_r4044890985


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/modern/TopicIds.java:
##########
@@ -226,12 +228,41 @@ public Iterator<Uuid> iterator() {
 
     @Override
     public Object[] toArray() {
-        throw new UnsupportedOperationException();
+        var topicIds = new Object[topicNames.size()];
+        var count = fill(topicIds);
+        return count == topicIds.length ? topicIds : Arrays.copyOf(topicIds, 
count);
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public <T> T[] toArray(T[] a) {
-        throw new UnsupportedOperationException();
+        var size = topicNames.size();
+        var topicIds = a.length >= size
+            ? a
+            : (T[]) Array.newInstance(a.getClass().getComponentType(), size);
+        var count = fill(topicIds);
+        if (count < topicIds.length) {
+            if (topicIds == a) {
+                topicIds[count] = null;
+            } else {
+                topicIds = Arrays.copyOf(topicIds, count);
+            }
+        }
+        return topicIds;
+    }
+
+    /**
+     * Fills the array with the ids of the topic names which resolve, in 
iteration order.
+     *
+     * @return The number of ids, which is below the size when a topic name 
has no id, its
+     *         topic having been deleted.
+     */
+    private int fill(Object[] topicIds) {
+        var count = 0;
+        for (var topicId : this) {
+            topicIds[count++] = topicId;
+        }
+        return count;
     }

Review Comment:
   I did consider it but I prefer to keep the explicit 
`UnsupportedOperationException` on all the mutation paths.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to