From 7b3854218303f6631da69d09d951470e090db377 Mon Sep 17 00:00:00 2001 From: lvtianyu Date: Fri, 23 Feb 2018 10:41:49 +0800 Subject: [PATCH] fix(dbsync): json column of zero length has no value, value parsing should be skipped --- .../dbsync/binlog/event/RowsLogBuffer.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/RowsLogBuffer.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/RowsLogBuffer.java index 459da9cc..276defba 100644 --- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/RowsLogBuffer.java +++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/RowsLogBuffer.java @@ -969,17 +969,17 @@ public final class RowsLogBuffer { default: throw new IllegalArgumentException("!! Unknown JSON packlen = " + meta); } - // len = buffer.getUint16(); - // buffer.forward(meta - 4); - int position = buffer.position(); - Json_Value jsonValue = JsonConversion.parse_value(buffer.getUint8(), buffer, len - 1, charsetName); - StringBuilder builder = new StringBuilder(); - jsonValue.toJsonString(builder, charsetName); - value = builder.toString(); - buffer.position(position + len); - // byte[] binary = new byte[len]; - // buffer.fillBytes(binary, 0, len); - // value = binary; + if (0 == len) { + // fixed issue #1 by lava, json column of zero length has no value, value parsing should be skipped + value = ""; + } else { + int position = buffer.position(); + Json_Value jsonValue = JsonConversion.parse_value(buffer.getUint8(), buffer, len - 1, charsetName); + StringBuilder builder = new StringBuilder(); + jsonValue.toJsonString(builder, charsetName); + value = builder.toString(); + buffer.position(position + len); + } javaType = Types.VARCHAR; length = len; break;