{"id":"03af3f1383277397","repo":"apache/kafka","slug":"the-topiccollection-topics-provided-did-not-mat-03af3f","errorCode":null,"errorMessage":"The TopicCollection: {topics} provided did not match any supported classes for describeTopics.","messagePattern":"The TopicCollection: (.+?) provided did not match any supported classes for describeTopics\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java","lineNumber":2248,"sourceCode":"                topicListingFuture.complete(topicListing);\n            }\n\n            @Override\n            void handleFailure(Throwable throwable) {\n                topicListingFuture.completeExceptionally(throwable);\n            }\n        }, now);\n        return new ListTopicsResult(topicListingFuture);\n    }\n\n    @Override\n    public DescribeTopicsResult describeTopics(final TopicCollection topics, DescribeTopicsOptions options) {\n        if (topics instanceof TopicIdCollection)\n            return DescribeTopicsResult.ofTopicIds(handleDescribeTopicsByIds(((TopicIdCollection) topics).topicIds(), options));\n        else if (topics instanceof TopicNameCollection)\n            return DescribeTopicsResult.ofTopicNames(handleDescribeTopicsByNamesWithDescribeTopicPartitionsApi(((TopicNameCollection) topics).topicNames(), options));\n        else\n            throw new IllegalArgumentException(\"The TopicCollection: \" + topics + \" provided did not match any supported classes for describeTopics.\");\n    }\n\n    private Call generateDescribeTopicsCallWithMetadataApi(\n        List<String> topicNamesList,\n        Map<String, KafkaFutureImpl<TopicDescription>> topicFutures,\n        DescribeTopicsOptions options,\n        long now\n    ) {\n        return new Call(\"describeTopics\", calcDeadlineMs(now, options.timeoutMs()),\n            new LeastLoadedNodeProvider()) {\n\n            private boolean supportsDisablingTopicCreation = true;\n\n            @Override\n            MetadataRequest.Builder createRequest(int timeoutMs) {\n                if (supportsDisablingTopicCreation)\n                    return new MetadataRequest.Builder(new MetadataRequestData()\n                        .setTopics(convertToMetadataRequestTopic(topicNamesList))","sourceCodeStart":2230,"sourceCodeEnd":2266,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java#L2230-L2266","documentation":"Thrown by KafkaAdminClient.describeTopics(TopicCollection, DescribeTopicsOptions) when the passed TopicCollection is neither a TopicIdCollection nor a TopicNameCollection. Like deleteTopics, describeTopics dispatches on these two concrete subtypes (handleDescribeTopicsByIds vs handleDescribeTopicsByNamesWithDescribeTopicPartitionsApi); any other TopicCollection implementation has no defined RPC mapping and is rejected with IllegalArgumentException.","triggerScenarios":"Calling admin.describeTopics(topicCollection, opts) with a TopicCollection that is not a TopicIdCollection or TopicNameCollection — e.g. a custom subclass, a mock, or a placeholder constructed outside the supported factories.","commonSituations":"Custom wrapper abstraction over TopicCollection; version/fork mismatch; reflection-built collection object; test code passing a stubbed TopicCollection.","solutions":["Build the collection with TopicCollection.ofTopicNames(names) or TopicCollection.ofTopicIds(ids), or call the convenience admin.describeTopics(Collection<String>) overload.","If you must subclass TopicCollection, extend TopicNameCollection or TopicIdCollection so the dispatch instanceof matches.","Do not pass custom TopicCollection implementations to describeTopics(TopicCollection, DescribeTopicsOptions)."],"exampleFix":"// before - custom TopicCollection subclass\nadmin.describeTopics(myCustomTopicCollection, new DescribeTopicsOptions()); // throws\n\n// after\nTopicCollection topics = TopicCollection.ofTopicIds(List.of(topicId1, topicId2));\nadmin.describeTopics(topics, new DescribeTopicsOptions());","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isSupportedTopicCollection(TopicCollection c) {\n    return c instanceof TopicIdCollection || c instanceof TopicNameCollection;\n}","tryCatchPattern":"if (!(topics instanceof TopicIdCollection || topics instanceof TopicNameCollection)) {\n    throw new IllegalArgumentException(\"Use TopicCollection.ofTopicNames(...) or TopicCollection.ofTopicIds(...)\");\n}\nadmin.describeTopics(topics, options);","preventionTips":["Only the two shipped TopicCollection subtypes are accepted by describeTopics; build them with TopicCollection.ofTopicNames(...)/ofTopicIds(...).","Keep a single factory method in your codebase that returns TopicCollection so an unsupported subtype never reaches the API.","Mirror the same guard used for deleteTopics — both APIs enforce the identical type check."],"tags":["admin-client","topic-management","argument-validation","api-contract"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}