{"record":{"id":"6c76f1e6e17eb99b","repo":"apache/rocketmq","slug":"the-specified-topic-is-blank","errorCode":null,"errorMessage":"The specified topic is blank","messagePattern":"The specified topic is blank","errorType":"validation","errorClass":"MQClientException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/Validators.java","lineNumber":97,"sourceCode":"        if (0 == msg.getBody().length) {\n            throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, \"the message body length is zero\");\n        }\n\n        if (msg.getBody().length > defaultMQProducer.getMaxMessageSize()) {\n            throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL,\n                \"the message body size over max value, MAX: \" + defaultMQProducer.getMaxMessageSize());\n        }\n\n        String lmqPath = msg.getUserProperty(MessageConst.PROPERTY_INNER_MULTI_DISPATCH);\n        if (StringUtils.contains(lmqPath, File.separator)) {\n            throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL,\n                \"INNER_MULTI_DISPATCH \" + lmqPath + \" can not contains \" + File.separator + \" character\");\n        }\n    }\n\n    public static void checkTopic(String topic) throws MQClientException {\n        if (UtilAll.isBlank(topic)) {\n            throw new MQClientException(\"The specified topic is blank\", null);\n        }\n\n        if (topic.length() > TOPIC_MAX_LENGTH) {\n            throw new MQClientException(\n                String.format(\"The specified topic is longer than topic max length %d.\", TOPIC_MAX_LENGTH), null);\n        }\n\n        if (isTopicOrGroupIllegal(topic)) {\n            throw new MQClientException(String.format(\n                    \"The specified topic[%s] contains illegal characters, allowing only %s\", topic,\n                    \"^[%|a-zA-Z0-9_-]+$\"), null);\n        }\n    }\n\n    public static void isSystemTopic(String topic) throws MQClientException {\n        if (TopicValidator.isSystemTopic(topic)) {\n            throw new MQClientException(\n                    String.format(\"The topic[%s] is conflict with system topic.\", topic), null);","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/Validators.java#L79-L115","documentation":"Validators.checkTopic rejects a topic that is null, empty, or whitespace-only. The check runs at the top of checkMessage and on subscribe/admin calls; without a topic the client cannot route the request, so it fails immediately with MQClientException (no code set).","triggerScenarios":"new Message(null/\"\", body); consumer.subscribe(\"\", \"*\"); topic read from config that resolved blank; topic variable from a map.get() returning null.","commonSituations":"Missing 'rocketmq.producer.topic' property in Spring config; dynamic topic resolution failing silently to empty; refactoring constants and the topic constant left unset.","solutions":["Pass a concrete topic name in the Message constructor / subscribe call.","Fail fast on startup if the topic property is missing: Objects.requireNonNull(config.getTopic()).","Centralize topic names as constants to avoid typos and unset variables."],"exampleFix":"// before\nproducer.send(new Message(System.getenv(\"TOPIC\"), tag, body)); // env var unset -> null\n\n// after\nString topic = Objects.requireNonNull(System.getenv(\"TOPIC\"), \"TOPIC env var must be set\");\nproducer.send(new Message(topic, tag, body));","handlingStrategy":"validation","validationCode":"static String requireTopic(String topic) {\n    if (topic == null || topic.isBlank()) {\n        throw new IllegalArgumentException(\"topic must be non-blank\");\n    }\n    return topic;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fail fast at startup if topic config is missing.","Keep topics as constants/enums in one place.","Check dynamic topic lookups for null before constructing the Message."],"tags":["rocketmq","topic","validation","null-check","configuration"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}