deployed 2.0.7.RELEASE,增加MapConverter鲁棒性,并记录错误信息

master
剑器近 2021-10-27 17:41:25 +08:00
parent a802097a21
commit aad9821481
2 changed files with 24 additions and 16 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>io.github.yezhihao</groupId> <groupId>io.github.yezhihao</groupId>
<artifactId>protostar</artifactId> <artifactId>protostar</artifactId>
<version>2.0.6.RELEASE</version> <version>2.0.7.RELEASE</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Protostar</name> <name>Protostar</name>
@ -33,10 +33,10 @@
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<resource.delimiter>@</resource.delimiter> <resource.delimiter>@</resource.delimiter>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>${java.version}</maven.compiler.source> <maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target> <maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.test.skip>true</maven.test.skip> <maven.test.skip>true</maven.test.skip>
</properties> </properties>
@ -62,7 +62,7 @@
<dependency> <dependency>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId> <artifactId>netty-buffer</artifactId>
<version>4.1.68.Final</version> <version>4.1.69.Final</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -25,19 +25,27 @@ public abstract class MapConverter<K, V> extends PrepareLoadStrategy implements
if (!input.isReadable()) if (!input.isReadable())
return null; return null;
Map<K, V> map = new TreeMap<>(); Map<K, V> map = new TreeMap<>();
do { K key = null;
K key = readKey(input); int length = 0;
int length = ByteBufUtils.readInt(input, valueSize()); try {
do {
key = readKey(input);
length = ByteBufUtils.readInt(input, valueSize());
if (length <= 0)
continue;
if (input.isReadable(length)) { if (input.isReadable(length)) {
int writerIndex = input.writerIndex(); int writerIndex = input.writerIndex();
input.writerIndex(input.readerIndex() + length); input.writerIndex(input.readerIndex() + length);
map.put(key, (V) readValue(key, input)); map.put(key, (V) readValue(key, input));
input.writerIndex(writerIndex); input.writerIndex(writerIndex);
} else { } else {
map.put(key, (V) readValue(key, input)); map.put(key, (V) readValue(key, input));
} }
} while (input.isReadable()); } while (input.isReadable());
} catch (Exception e) {
log.warn("解析出错:KEY[{}], LENGTH[{}]", key, length);
}
return map; return map;
} }