{"record":{"id":"cc40fecef0ac84a9","repo":"alibaba/canal","slug":"unexpected-binlog-image-query-result-rs-getfiel","errorCode":null,"errorMessage":"unexpected binlog image query result: + rs.getFieldValues()","messagePattern":"unexpected binlog image query result: \\+ rs\\.getFieldValues\\(\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/MysqlConnection.java","lineNumber":557,"sourceCode":"     */\n    private void loadBinlogImage() {\n        ResultSetPacket rs = null;\n        try {\n            rs = query(\"show variables like 'binlog_row_image'\");\n        } catch (IOException e) {\n            throw new CanalParseException(e);\n        }\n\n        List<String> columnValues = rs.getFieldValues();\n        if (columnValues == null || columnValues.size() != 2) {\n            // 可能历时版本没有image特性\n            binlogImage = BinlogImage.FULL;\n        } else {\n            binlogImage = BinlogImage.valuesOf(columnValues.get(1));\n        }\n\n        if (binlogFormat == null) {\n            throw new IllegalStateException(\"unexpected binlog image query result:\" + rs.getFieldValues());\n        }\n    }\n\n    /**\n     * 获取主库checksum信息\n     * \n     * <pre>\n     * mariadb区别于mysql会在binlog的第一个事件Rotate_Event里也会采用checksum逻辑,而mysql是在第二个binlog事件之后才感知是否需要处理checksum\n     * 导致maraidb只要是开启checksum就会出现binlog文件名解析乱码\n     * fixed issue : https://github.com/alibaba/canal/issues/1081\n     * </pre>\n     */\n    private void loadBinlogChecksum() {\n        ResultSetPacket rs = null;\n        try {\n            rs = query(\"select @@global.binlog_checksum\");\n            List<String> columnValues = rs.getFieldValues();\n            if (columnValues != null && columnValues.size() >= 1 && columnValues.get(0) != null","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/MysqlConnection.java#L539-L575","documentation":"In loadBinlogImage(), the field-count guard tolerates missing binlog_row_image (old versions default to FULL), but the final check throws IllegalStateException when binlogFormat == null. Note this is a latent bug: the guard checks binlogFormat (a field set by loadBinlogFormat) instead of binlogImage, so this fires when the binlog format was never loaded — typically when loadBinlogImage runs but loadBinlogFormat did not run first or failed silently.","triggerScenarios":"loadBinlogImage() executes and binlogFormat is still null — either loadBinlogFormat was skipped, threw and was swallowed, or the field was reset. The error message misleadingly blames the image query result.","commonSituations":"Custom call ordering that invokes loadBinlogImage() without a preceding successful loadBinlogFormat(); a prior loadBinlogFormat() that set binlogFormat=null via an unrecognized value (though that path throws first); test wiring that constructs the connection without full initialization.","solutions":["Ensure loadBinlogFormat() runs and succeeds before loadBinlogImage() (updateSettings() is the normal entry that sequences these).","Confirm the account can read `show variables like 'binlog_format'` so binlogFormat is populated.","If patching canal, fix the guard at line 556 to check `binlogImage == null` instead of `binlogFormat == null` — the current condition is a copy-paste defect."],"exampleFix":"// defect at MysqlConnection.java:556 — checks the wrong field\nif (binlogFormat == null) {\n    throw new IllegalStateException(\"unexpected binlog image query result:\" + rs.getFieldValues());\n}\n// corrected guard:\nif (binlogImage == null) {\n    throw new IllegalStateException(\"unexpected binlog image query result:\" + rs.getFieldValues());\n}","handlingStrategy":"try-catch","validationCode":"// Ensure loadBinlogFormat succeeded before loadBinlogImage runs\nif (connection.getBinlogFormat() == null) {\n    throw new IllegalStateException(\"binlogFormat not loaded; cannot safely load binlog image\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    connection.loadBinlogFormat();\n    connection.loadBinlogImage();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"unexpected binlog image query result\")) {\n        logger.error(\"binlogImage guard fired on null binlogFormat (known copy-paste defect); ensure loadBinlogFormat ran first\", e);\n    }\n    throw e;\n}","preventionTips":["Always run loadBinlogFormat() before loadBinlogImage() via updateSettings().","If patching canal, correct the guard at line 556 to check binlogImage, not binlogFormat.","Add an integration test asserting binlogImage is populated after initialization."],"tags":["mysql","binlog-image","bug","metadata-query","canal-parse"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}