{"record":{"id":"50c309e21b5a1adb","repo":"apache/kafka","slug":"topicidfutures-and-namefutures-cannot-both-be-spec","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/DeleteTopicsResult.java","lineNumber":38,"sourceCode":"import org.apache.kafka.common.KafkaFuture;\nimport org.apache.kafka.common.TopicCollection;\nimport org.apache.kafka.common.Uuid;\nimport org.apache.kafka.common.annotation.InterfaceAudience;\n\nimport java.util.Collection;\nimport java.util.Map;\n\n/**\n * The result of the {@link Admin#deleteTopics(Collection)} call.\n */\n@InterfaceAudience.Public\npublic class DeleteTopicsResult {\n    private final Map<Uuid, KafkaFuture<Void>> topicIdFutures;\n    private final Map<String, KafkaFuture<Void>> nameFutures;\n\n    protected DeleteTopicsResult(Map<Uuid, KafkaFuture<Void>> topicIdFutures, Map<String, KafkaFuture<Void>> 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 DeleteTopicsResult ofTopicIds(Map<Uuid, KafkaFuture<Void>> topicIdFutures) {\n        return new DeleteTopicsResult(topicIdFutures, null);\n    }\n\n    static DeleteTopicsResult ofTopicNames(Map<String, KafkaFuture<Void>> nameFutures) {\n        return new DeleteTopicsResult(null, nameFutures);\n    }\n\n    /**\n     * Use when {@link Admin#deleteTopics(TopicCollection, DeleteTopicsOptions)} used a TopicIdCollection\n     * @return a map from topic IDs to futures which can be used to check the status of\n     * individual deletions if the deleteTopics request used topic IDs. Otherwise return null.","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/admin/DeleteTopicsResult.java#L20-L56","documentation":"Thrown by the DeleteTopicsResult protected constructor when both topicIdFutures and nameFutures are non-null. The result object is designed to hold exactly one kind of future map — either by topic ID (Uuid) or by topic name — never both. Use the static factories ofTopicIds / ofTopicNames to construct correctly.","triggerScenarios":"Directly instantiating DeleteTopicsResult (or a subclass constructor) with both the topicIdFutures map and nameFutures map non-null.","commonSituations":"A subclass or test code calls the protected constructor with both arguments, violating the either/or invariant. Normal usage goes through the static factory methods, so this is primarily a developer/extension error.","solutions":["Use DeleteTopicsResult.ofTopicIds(...) or ofTopicNames(...) instead of the constructor.","If subclassing, pass null for the unused map parameter.","Add a unit test verifying the subclass construction does not supply both maps."],"exampleFix":"// before\nnew DeleteTopicsResult(idMap, nameMap); // both non-null\n\n// after\nDeleteTopicsResult.ofTopicIds(idMap);   // or\nDeleteTopicsResult.ofTopicNames(nameMap);","handlingStrategy":"validation","validationCode":"// Always use the static factories; never pass both maps\nDeleteTopicsResult result = useTopicIds\n    ? DeleteTopicsResult.ofTopicIds(idMap)\n    : DeleteTopicsResult.ofTopicNames(nameMap);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call the protected constructor directly; use ofTopicIds / ofTopicNames.","In subclasses, enforce the either/or invariant before calling super.","Add unit tests covering both single-map construction paths."],"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"}