diff --git a/pom.xml b/pom.xml
index 3f164298..5982049a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
4.0.0
com.alipay.sofa
bolt
- 1.5.7
+ 1.5.8
jar
${project.groupId}:${project.artifactId}
diff --git a/src/main/java/com/alipay/remoting/config/switches/ProtocolSwitch.java b/src/main/java/com/alipay/remoting/config/switches/ProtocolSwitch.java
index aad3e38b..ac91a17a 100644
--- a/src/main/java/com/alipay/remoting/config/switches/ProtocolSwitch.java
+++ b/src/main/java/com/alipay/remoting/config/switches/ProtocolSwitch.java
@@ -114,7 +114,7 @@ public static byte toByte(BitSet bs) {
throw new IllegalArgumentException("The byte value " + value
+ " generated according to bit set " + bs
+ " is out of range, should be limited between ["
- + Byte.MIN_VALUE + "] to [" + Byte.MAX_VALUE + "]");
+ + 0 + "] to [" + Byte.MAX_VALUE + "]");
}
return (byte) value;
}
@@ -125,10 +125,10 @@ public static byte toByte(BitSet bs) {
* @return bit set represent the byte
*/
public static BitSet toBitSet(int value) {
- if (value > Byte.MAX_VALUE || value < Byte.MIN_VALUE) {
+ if (value < 0 || value > Byte.MAX_VALUE) {
throw new IllegalArgumentException(
- "The value " + value + " is out of byte range, should be limited between ["
- + Byte.MIN_VALUE + "] to [" + Byte.MAX_VALUE + "]");
+ "The value " + value + " is out of byte range, should be limited between [" + 0
+ + "] to [" + Byte.MAX_VALUE + "]");
}
BitSet bs = new BitSet();
int index = 0;
diff --git a/src/test/java/com/alipay/remoting/ProtocolTest.java b/src/test/java/com/alipay/remoting/ProtocolTest.java
new file mode 100644
index 00000000..c2caf701
--- /dev/null
+++ b/src/test/java/com/alipay/remoting/ProtocolTest.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.alipay.remoting;
+
+import com.alipay.remoting.rpc.protocol.RpcProtocolV2;
+import sun.security.ssl.ProtocolVersion;
+
+/**
+ * @author chengyi (mark.lx@antfin.com) 2021-05-21 11:15
+ */
+public class ProtocolTest {
+ public static void main(String[] args) {
+ System.out.println(ProtocolCode.fromBytes(RpcProtocolV2.PROTOCOL_CODE));
+ }
+}
diff --git a/src/test/java/com/alipay/remoting/inner/utiltest/ProtocolSwitchTest.java b/src/test/java/com/alipay/remoting/inner/utiltest/ProtocolSwitchTest.java
index 9bbb5190..201d1fbd 100644
--- a/src/test/java/com/alipay/remoting/inner/utiltest/ProtocolSwitchTest.java
+++ b/src/test/java/com/alipay/remoting/inner/utiltest/ProtocolSwitchTest.java
@@ -187,6 +187,15 @@ public void test_byteToBitSet() {
for (int i = 0; i <= 6; ++i) {
Assert.assertTrue(bs.get(i));
}
+
+ Exception exception = null;
+ try {
+ ProtocolSwitch.toBitSet(-1);
+ } catch (Exception e) {
+ exception = e;
+ }
+ Assert.assertNotNull(exception);
+ Assert.assertTrue(exception instanceof IllegalArgumentException);
}
@Test