{"record":{"id":"f049ca90bf823113","repo":"apache/shardingsphere","slug":"wrong-length-d-of-mysql-type-date","errorCode":null,"errorMessage":"Wrong length `%d` of MYSQL_TYPE_DATE","messagePattern":"Wrong length `(.+?)` of MYSQL_TYPE_DATE","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/MySQLTimeBinaryProtocolValue.java","lineNumber":48,"sourceCode":"/**\n * Binary protocol value for time for MySQL.\n */\npublic final class MySQLTimeBinaryProtocolValue implements MySQLBinaryProtocolValue {\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                return new Timestamp(0L);\n            case 8:\n                return getTimestamp(payload);\n            case 12:\n                Timestamp result = getTimestamp(payload);\n                result.setNanos(payload.readInt4() * 1000);\n                return result;\n            default:\n                throw new SQLFeatureNotSupportedException(String.format(\"Wrong length `%d` of MYSQL_TYPE_DATE\", length));\n        }\n    }\n    \n    private Timestamp getTimestamp(final MySQLPacketPayload payload) {\n        payload.readInt1();\n        payload.readInt4();\n        Timestamp result = Timestamp.valueOf(LocalDateTime.of(0, 1, 1, payload.readInt1(), payload.readInt1(), payload.readInt1()));\n        result.setNanos(0);\n        return result;\n    }\n    \n    @Override\n    public void write(final MySQLPacketPayload payload, final Object value) {\n        LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(((Time) value).getTime()), ZoneId.systemDefault());\n        int hours = localDateTime.getHour();\n        int minutes = localDateTime.getMinute();\n        int seconds = localDateTime.getSecond();\n        int nanos = localDateTime.getNano();","sourceCodeStart":30,"sourceCodeEnd":66,"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/MySQLTimeBinaryProtocolValue.java#L30-L66","documentation":"Thrown when a MySQL binary-protocol TIME value has a length byte other than 0 (zero time), 8 (time), or 12 (time with microseconds). Note the message says MYSQL_TYPE_DATE although it is thrown by the TIME reader in MySQLTimeBinaryProtocolValue — the names are swapped relative to the DATE class. Any other length indicates malformed data or stream desynchronization.","triggerScenarios":"MySQLTimeBinaryProtocolValue.read() gets a length byte not in {0,8,12} — corrupted packet, reader misalignment after a previous column, or a nonstandard server encoding.","commonSituations":"Binary prepared-statement resultsets containing TIME columns read after a wrongly-sized earlier field; non-MySQL clients on the MySQL port; forks with divergent binary TIME encodings.","solutions":["Treat the 'DATE' text as a known mislabel; the failing value is a TIME column","Verify the preceding columns' binary sizes to rule out reader desynchronization; test with text protocol (useServerPrepStmts=false)","Check the server is stock MySQL at a supported version","Report upstream with server version, column types, and the failing length value"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    value = timeBinaryProtocolValue.read(payload, unsigned);\n} catch (SQLFeatureNotSupportedException ex) {\n    // length not in {0,8,12}: capture the resultset bytes and compare against the MySQL binary protocol spec\n    log.warn(\"binary time decode failed: {}\", ex.getMessage());\n    throw ex;\n}","preventionTips":["Remember the message says DATE but the failure is in the TIME reader","Verify earlier columns decode with correct widths to rule out desync before suspecting the TIME value itself"],"tags":["mysql","binary-protocol","time","packet-parsing","misleading-message"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}