{"record":{"id":"f42292c459206b30","repo":"apache/shardingsphere","slug":"wrong-length-d-of-mysql-type-time","errorCode":null,"errorMessage":"Wrong length `%d` of MYSQL_TYPE_TIME","messagePattern":"Wrong length `(.+?)` of MYSQL_TYPE_TIME","errorType":"exception","errorClass":"SQLFeatureNotSupportedException","httpStatus":null,"severity":"error","filePath":"database/protocol/dialect/mysql/src/main/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLDateBinaryProtocolValue.java","lineNumber":52,"sourceCode":"    \n    private static final long NANOS_PER_SECOND = 1_000_000_000L;\n    \n    @Override\n    public Object read(final MySQLPacketPayload payload, final boolean unsigned) throws SQLException {\n        int length = payload.readInt1();\n        switch (length) {\n            case 0:\n                throw new SQLFeatureNotSupportedException(\"Can not support date format if year, month, day is absent.\");\n            case 4:\n                return getTimestampForDate(payload);\n            case 7:\n                return getTimestampForDatetime(payload);\n            case 11:\n                Timestamp result = getTimestampForDatetime(payload);\n                result.setNanos(payload.readInt4() * 1000);\n                return result;\n            default:\n                throw new SQLFeatureNotSupportedException(String.format(\"Wrong length `%d` of MYSQL_TYPE_TIME\", length));\n        }\n    }\n    \n    private Timestamp getTimestampForDate(final MySQLPacketPayload payload) {\n        return Timestamp.valueOf(LocalDate.of(payload.readInt2(), payload.readInt1(), payload.readInt1()).atStartOfDay());\n    }\n    \n    private Timestamp getTimestampForDatetime(final MySQLPacketPayload payload) {\n        return Timestamp.valueOf(LocalDateTime.of(payload.readInt2(), payload.readInt1(), payload.readInt1(), payload.readInt1(), payload.readInt1(), payload.readInt1()));\n    }\n    \n    @Override\n    public void write(final MySQLPacketPayload payload, final Object value) {\n        LocalDateTime dateTime;\n        if (value instanceof LocalDate) {\n            dateTime = ((LocalDate) value).atStartOfDay();\n        } else {\n            dateTime = value instanceof LocalDateTime ? (LocalDateTime) value : new Timestamp(((Date) value).getTime()).toLocalDateTime();","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/database/protocol/dialect/mysql/src/main/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLDateBinaryProtocolValue.java#L34-L70","documentation":"Thrown when a MySQL binary-protocol date value has an unexpected length byte: only 0 (zero date, itself rejected separately), 4 (date), 7 (datetime), and 11 (datetime with microseconds) are valid. Any other length means the binary value is malformed or the reader is misaligned. Note the message text says MYSQL_TYPE_TIME but is produced by the DATE reader in MySQLDateBinaryProtocolValue — a copy-paste wording issue.","triggerScenarios":"MySQLDateBinaryProtocolValue.read() receives a length byte other than 0/4/7/11 — from a corrupted packet, a reader desynced after earlier fields, or a server/fork emitting a nonstandard encoding.","commonSituations":"Packet stream misalignment after a wrongly-parsed preceding column; connecting non-MySQL clients to the MySQL port; very new server versions changing binary date encoding.","solutions":["Ignore the 'TIME' wording — the failure is in the DATE/DATETIME binary reader; identify which column was being parsed","Capture the binary resultset (e.g. with a proxy/Wireshark) and verify the length byte of each date value against the MySQL binary protocol","Test the same query with useServerPrepStmts=false to bypass the binary protocol and confirm data integrity","Report upstream with the server version and failing row if a standard server reproduces it"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    value = dateBinaryProtocolValue.read(payload, unsigned);\n} catch (SQLFeatureNotSupportedException ex) {\n    // length not in {0,4,7,11}: stream or data is corrupt; re-run the query over text protocol to confirm\n    log.warn(\"binary date decode failed: {}\", ex.getMessage());\n    throw ex;\n}","preventionTips":["Note the message mislabel (says TIME, thrown by the DATE reader) to avoid debugging the wrong path","Keep a text-protocol fallback path (useServerPrepStmts=false) for diagnosis"],"tags":["mysql","binary-protocol","date","packet-parsing","misleading-message"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}