Skip to content

Commit

Permalink
fix protocol switch
Browse files Browse the repository at this point in the history
  • Loading branch information
dbl-x committed Aug 23, 2021
2 parents 05be87a + 5e37c2d commit 8114247
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alipay.sofa</groupId>
<artifactId>bolt</artifactId>
<version>1.5.7</version>
<version>1.5.8</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/com/alipay/remoting/ProtocolTest.java
Original file line number Diff line number Diff line change
@@ -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 ([email protected]) 2021-05-21 11:15
*/
public class ProtocolTest {
public static void main(String[] args) {
System.out.println(ProtocolCode.fromBytes(RpcProtocolV2.PROTOCOL_CODE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8114247

Please sign in to comment.