{"record":{"id":"ff0216a6c8927d9f","repo":"alibaba/canal","slug":"topic-cannot-null","errorCode":null,"errorMessage":"topic cannot null","messagePattern":"topic cannot null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/alibaba/otter/canal/common/utils/MQUtil.java","lineNumber":52,"sourceCode":"\n    /**\n     * 判断tag是否是正则\n     *\n     * @param tag\n     * @return\n     */\n    public static boolean isPatternTag(String tag) {\n        return !tag.matches(\"^[0-9a-zA-Z]+$\");\n    }\n\n    /**\n     * 检查topic有效性\n     *\n     * @param topics\n     */\n    public static void checkTopicWithErr(String... topics) {\n        if (null == topics || 0 == topics.length) {\n            throw new NullPointerException(\"topic cannot null\");\n        }\n\n        if (1 == topics.length) {\n            boolean ok = checkTopic(topics[0]);\n            if (ok) {\n                return;\n            }\n            throw new RuntimeException(\"topic invalid: \" + topics[0]);\n        }\n\n        for (String t : topics) {\n            if (!checkTopic(t)) {\n                throw new IllegalArgumentException(\"topic invalid: \" + t);\n            }\n            if (isPatternTopic(t)) {\n                throw new RuntimeException(\"pattern topic cannot multi: \" + t);\n            }\n        }","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/common/src/main/java/com/alibaba/otter/canal/common/utils/MQUtil.java#L34-L70","documentation":"Thrown by MQUtil.checkTopicWithErr() when the topics varargs array is null or has zero length. This is a pre-condition check before any topic validation logic runs. The exception type is NullPointerException, which is slightly misleading since it is an explicit guard rather than an unexpected null dereference.","triggerScenarios":"Calling MQUtil.checkTopicWithErr() with no arguments, passing null explicitly, or passing a zero-length String array.","commonSituations":"Canal MQ configuration has no topic specified (empty or null canal.mq.topic); programmatic MQ producer setup omits the topic parameter; config parsing produces an empty topic list.","solutions":["Provide at least one non-null topic string when calling checkTopicWithErr().","Verify canal.mq.topic (or the equivalent config property) is set to a non-empty value in canal.properties or the destination config.","Add a null/empty check before calling the method if the topic source may be absent."],"exampleFix":"// before\ncanal.mq.topic=\n// or programmatic\nMQUtil.checkTopicWithErr(); // no topics\n\n// after\ncanal.mq.topic=example-topic\n// programmatic\nMQUtil.checkTopicWithErr(\"example-topic\");","handlingStrategy":"validation","validationCode":"// Validate topics are non-null and non-empty before calling checkTopicWithErr\nif (topics == null || topics.length == 0) {\n    throw new IllegalArgumentException(\"At least one topic must be specified\");\n}\nMQUtil.checkTopicWithErr(topics);","typeGuard":"null","tryCatchPattern":"try {\n    MQUtil.checkTopicWithErr(topics);\n} catch (NullPointerException e) {\n    if (\"topic cannot null\".equals(e.getMessage())) {\n        logger.error(\"No MQ topic configured. Set canal.mq.topic in canal.properties.\");\n    }\n    throw e;\n}","preventionTips":["Always set canal.mq.topic to a non-empty value in the MQ producer configuration.","Validate topic configuration at startup before the MQ producer initializes.","Add config-file validation that checks for required MQ properties."],"tags":["mq","topic-validation","required-field","config-error"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}