{"record":{"id":"ad246f2bae74e83a","repo":"apache/kafka","slug":"the-topiccollection-topics-provided-did-not-mat","errorCode":null,"errorMessage":"The TopicCollection: {topics} provided did not match any supported classes for deleteTopics.","messagePattern":"The TopicCollection: (.+?) provided did not match any supported classes for deleteTopics\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java","lineNumber":2013,"sourceCode":"                // If there were any topics retries due to a quota exceeded exception, we propagate\n                // the initial error back to the caller if the request timed out.\n                maybeCompleteQuotaExceededException(options.shouldRetryOnQuotaViolation(),\n                    throwable, futures, quotaExceededExceptions, (int) (time.milliseconds() - now));\n                // Fail all the other remaining futures\n                completeAllExceptionally(futures.values(), throwable);\n            }\n        };\n    }\n\n    @Override\n    public DeleteTopicsResult deleteTopics(final TopicCollection topics,\n                                           final DeleteTopicsOptions options) {\n        if (topics instanceof TopicIdCollection)\n            return DeleteTopicsResult.ofTopicIds(handleDeleteTopicsUsingIds(((TopicIdCollection) topics).topicIds(), options));\n        else if (topics instanceof TopicNameCollection)\n            return DeleteTopicsResult.ofTopicNames(handleDeleteTopicsUsingNames(((TopicNameCollection) topics).topicNames(), options));\n        else\n            throw new IllegalArgumentException(\"The TopicCollection: \" + topics + \" provided did not match any supported classes for deleteTopics.\");\n    }\n\n    private Map<String, KafkaFuture<Void>> handleDeleteTopicsUsingNames(final Collection<String> topicNames,\n                                                                        final DeleteTopicsOptions options) {\n        final Map<String, KafkaFutureImpl<Void>> topicFutures = new HashMap<>(topicNames.size());\n        final List<String> validTopicNames = new ArrayList<>(topicNames.size());\n        for (String topicName : topicNames) {\n            if (topicNameIsUnrepresentable(topicName)) {\n                KafkaFutureImpl<Void> future = new KafkaFutureImpl<>();\n                future.completeExceptionally(new InvalidTopicException(\"The given topic name '\" +\n                    topicName + \"' cannot be represented in a request.\"));\n                topicFutures.put(topicName, future);\n            } else if (!topicFutures.containsKey(topicName)) {\n                topicFutures.put(topicName, new KafkaFutureImpl<>());\n                validTopicNames.add(topicName);\n            }\n        }\n        if (!validTopicNames.isEmpty()) {","sourceCodeStart":1995,"sourceCodeEnd":2031,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java#L1995-L2031","documentation":"An IllegalArgumentException thrown by KafkaAdminClient.deleteTopics(TopicCollection, ...) when the TopicCollection subclass is neither TopicIdCollection nor TopicNameCollection. Only those two concrete subclasses are supported; anything else (including a custom or null subclass) is a programming error.","triggerScenarios":"Passing a custom TopicCollection subclass, or passing null cast to TopicCollection, to admin.deleteTopics(...). Subclassing TopicCollection in user code and expecting it to be honored.","commonSituations":"Library code that wraps TopicCollection with its own type; null returned from a helper that was expected to produce a collection; migrating between API versions where a third collection type was removed.","solutions":["Use TopicCollection.ofTopicNames(...) or TopicCollection.ofTopicIds(...) to build the collection.","Ensure the value passed is non-null and is one of the two supported concrete types.","If you have a custom wrapper, unwrap it to a supported TopicCollection before calling deleteTopics."],"exampleFix":"// before\nadmin.deleteTopics(myCustomTopicCollection, opts);\n\n// after\nadmin.deleteTopics(TopicCollection.ofTopicNames(Arrays.asList(\"t1\",\"t2\")), opts);","handlingStrategy":"validation","validationCode":"TopicCollection topics = (names != null && !names.isEmpty())\n    ? TopicCollection.ofTopicNames(names)\n    : TopicCollection.ofTopicIds(ids);\nadmin.deleteTopics(topics, options);","typeGuard":"static boolean isSupportedTopicCollection(TopicCollection c) {\n    return c instanceof TopicIdCollection || c instanceof TopicNameCollection;\n}","tryCatchPattern":null,"preventionTips":["Always build TopicCollection via the ofTopicNames/ofTopicIds factories.","Reject null before calling deleteTopics."],"tags":["kafka-admin","topic-management","argument-validation","api-misuse"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}