From aad9821481ef1fa9f59ef2ec5b93672c61bda800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=89=91=E5=99=A8=E8=BF=91?= Date: Wed, 27 Oct 2021 17:41:25 +0800 Subject: [PATCH] =?UTF-8?q?deployed=202.0.7.RELEASE=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0MapConverter=E9=B2=81=E6=A3=92=E6=80=A7=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E8=AE=B0=E5=BD=95=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 ++--- .../protostar/converter/MapConverter.java | 32 ++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index d24f9f4..a4d74bd 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 io.github.yezhihao protostar - 2.0.6.RELEASE + 2.0.7.RELEASE jar Protostar @@ -33,10 +33,10 @@ 1.8 @ - UTF-8 - UTF-8 ${java.version} ${java.version} + UTF-8 + UTF-8 true @@ -62,7 +62,7 @@ io.netty netty-buffer - 4.1.68.Final + 4.1.69.Final provided diff --git a/src/main/java/io/github/yezhihao/protostar/converter/MapConverter.java b/src/main/java/io/github/yezhihao/protostar/converter/MapConverter.java index 59bb9e4..01cfe43 100644 --- a/src/main/java/io/github/yezhihao/protostar/converter/MapConverter.java +++ b/src/main/java/io/github/yezhihao/protostar/converter/MapConverter.java @@ -25,19 +25,27 @@ public abstract class MapConverter extends PrepareLoadStrategy implements if (!input.isReadable()) return null; Map map = new TreeMap<>(); - do { - K key = readKey(input); - int length = ByteBufUtils.readInt(input, valueSize()); + K key = null; + int length = 0; + try { + do { + key = readKey(input); + length = ByteBufUtils.readInt(input, valueSize()); + if (length <= 0) + continue; - if (input.isReadable(length)) { - int writerIndex = input.writerIndex(); - input.writerIndex(input.readerIndex() + length); - map.put(key, (V) readValue(key, input)); - input.writerIndex(writerIndex); - } else { - map.put(key, (V) readValue(key, input)); - } - } while (input.isReadable()); + if (input.isReadable(length)) { + int writerIndex = input.writerIndex(); + input.writerIndex(input.readerIndex() + length); + map.put(key, (V) readValue(key, input)); + input.writerIndex(writerIndex); + } else { + map.put(key, (V) readValue(key, input)); + } + } while (input.isReadable()); + } catch (Exception e) { + log.warn("解析出错:KEY[{}], LENGTH[{}]", key, length); + } return map; }