{"record":{"id":"a8b12034bad086b5","repo":"apache/pulsar","slug":"could-not-apply-regex-when-read-topics-from-file","errorCode":null,"errorMessage":"Could not apply regex when read topics from file.","messagePattern":"Could not apply regex when read topics from file\\.","errorType":"validation","errorClass":"ParameterException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java","lineNumber":633,"sourceCode":"                \"--force\" }, description = \"Close all producer/consumer/replicator and delete topic forcefully\")\n        private boolean force = false;\n\n        @Option(names = {\"-d\", \"--deleteSchema\"}, description = \"Delete schema while deleting topic, \"\n                + \"but the parameter is invalid and the schema is always deleted\", hidden = true)\n        private boolean deleteSchema = false;\n\n        @Option(names = {\"-r\", \"regex\"},\n                description = \"Use a regex expression to match multiple topics for deletion.\")\n        boolean regex = false;\n\n        @Option(names = {\"--from-file\"}, description = \"Read a list of topics from a file for deletion.\")\n        boolean readFromFile;\n\n\n        @Override\n        void run() throws PulsarAdminException, IOException {\n            if (readFromFile && regex) {\n                throw new ParameterException(\"Could not apply regex when read topics from file.\");\n            }\n            if (readFromFile) {\n                List<String> topicsFromFile = Files.readAllLines(Path.of(topic));\n                for (String t : topicsFromFile) {\n                    try {\n                        getTopics().delete(t, force);\n                    } catch (Exception e) {\n                        print(\"Failed to delete topic: \" + t + \". Exception: \" + e);\n                    }\n                }\n            } else {\n                String topicName = validateTopicName(topic);\n                if (regex) {\n                    String namespace = TopicName.get(topic).getNamespace();\n                    List<String> topics = getTopics().getList(namespace);\n                    topics = topics.stream().filter(s -> s.matches(topicName)).toList();\n                    for (String t : topics) {\n                        try {","sourceCodeStart":615,"sourceCodeEnd":651,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java#L615-L651","documentation":"In CmdTopics.DeleteCmd, --read-from-file (which reads topic names line-by-line from a file) is mutually exclusive with --regex pattern matching; combining them is ambiguous and rejected up front with this ParameterException. No topics are deleted when this fires.","triggerScenarios":"Running 'pulsar-admin topics delete' with both --read-from-file and --regex flags present, e.g. a script accumulated flags from two different invocation styles.","commonSituations":"Wrapper scripts that always append --regex while adding --read-from-file for bulk deletions; users thinking the file contents can be regex patterns; copy-paste merging of two example commands.","solutions":["Remove the --regex flag and put literal topic names in the file, or","Remove --read-from-file and pass the regex pattern directly as the topic argument","Split the operation: filter the file first, then delete with literal names"],"exampleFix":"// before\npulsar-admin topics delete --read-from-file topics.txt --regex 'my-tenant/ns/.*'\n// after\npulsar-admin topics delete --read-from-file topics.txt\n// or\npulsar-admin topics delete 'my-tenant/ns/.*' --regex","handlingStrategy":"validation","validationCode":"if (readFromFile && regex) throw new IllegalArgumentException(\"--read-from-file and --regex are mutually exclusive\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat the two flags as mutually exclusive in wrapper scripts","For regex bulk delete, resolve patterns to names first, then use a file of literal names","Review accumulated flag sets in shared delete scripts"],"tags":["cli","pulsar-admin","conflicting-flags","topic-deletion"],"backgroundTag":"conflicting-arguments","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}