{"record":{"id":"3cfb6f81a51db14f","repo":"apache/kafka","slug":"topicidfutures-and-namefutures-cannot-both-be-spec-3cfb6f","errorCode":null,"errorMessage":"topicIdFutures and nameFutures cannot both be specified.","messagePattern":"topicIdFutures and nameFutures cannot both be specified\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/admin/DescribeTopicsResult.java","lineNumber":41,"sourceCode":"import org.apache.kafka.common.annotation.InterfaceAudience;\n\nimport java.util.Collection;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.concurrent.ExecutionException;\n\n/**\n * The result of the {@link KafkaAdminClient#describeTopics(Collection)} call.\n */\n@InterfaceAudience.Public\npublic class DescribeTopicsResult {\n    private final Map<Uuid, KafkaFuture<TopicDescription>> topicIdFutures;\n    private final Map<String, KafkaFuture<TopicDescription>> nameFutures;\n\n    // VisibleForTesting\n    protected DescribeTopicsResult(Map<Uuid, KafkaFuture<TopicDescription>> topicIdFutures, Map<String, KafkaFuture<TopicDescription>> nameFutures) {\n        if (topicIdFutures != null && nameFutures != null)\n            throw new IllegalArgumentException(\"topicIdFutures and nameFutures cannot both be specified.\");\n        if (topicIdFutures == null && nameFutures == null)\n            throw new IllegalArgumentException(\"topicIdFutures and nameFutures cannot both be null.\");\n        this.topicIdFutures = topicIdFutures;\n        this.nameFutures = nameFutures;\n    }\n\n    static DescribeTopicsResult ofTopicIds(Map<Uuid, KafkaFuture<TopicDescription>> topicIdFutures) {\n        return new DescribeTopicsResult(topicIdFutures, null);\n    }\n\n    static DescribeTopicsResult ofTopicNames(Map<String, KafkaFuture<TopicDescription>> nameFutures) {\n        return new DescribeTopicsResult(null, nameFutures);\n    }\n\n    /**\n     * Use when {@link Admin#describeTopics(TopicCollection, DescribeTopicsOptions)} used a TopicIdCollection\n     *\n     * @return a map from topic IDs to futures which can be used to check the status of","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/admin/DescribeTopicsResult.java#L23-L59","documentation":"Thrown by the DescribeTopicsResult protected constructor when both topicIdFutures and nameFutures are non-null. The result holds either a map keyed by topic ID (Uuid) or by topic name, but never both simultaneously — supplying both violates the object's invariant.","triggerScenarios":"Directly constructing DescribeTopicsResult (or a subclass) with both the topicIdFutures map and nameFutures map non-null.","commonSituations":"Test code or a subclass supplies both maps; the static factories ofTopicIds / ofTopicNames are the intended construction paths and avoid this.","solutions":["Use DescribeTopicsResult.ofTopicIds(...) or ofTopicNames(...) instead of the constructor.","If subclassing, pass null for the unused parameter.","Verify test fixtures do not construct the result with both maps."],"exampleFix":"// before\nnew DescribeTopicsResult(idMap, nameMap);\n\n// after\nDescribeTopicsResult.ofTopicIds(idMap);   // or\nDescribeTopicsResult.ofTopicNames(nameMap);","handlingStrategy":"validation","validationCode":"// Use static factories only\nDescribeTopicsResult result = useTopicIds\n    ? DescribeTopicsResult.ofTopicIds(idMap)\n    : DescribeTopicsResult.ofTopicNames(nameMap);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never construct DescribeTopicsResult directly; use ofTopicIds / ofTopicNames.","In subclasses, pass null for the unused map.","Add tests verifying single-map construction."],"tags":["validation","admin","invariant"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}