Skip to content

Commit 330dccc

Browse files
authored
[ISSUE #10107] Fix fastjson2 integer overflow when parsing AtomicLong (#10112)
1 parent bd1038a commit 330dccc

3 files changed

Lines changed: 30 additions & 12 deletions

File tree

WORKSPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ maven_install(
4141
artifacts = [
4242
"junit:junit:4.13.2",
4343
"com.alibaba:fastjson:1.2.76",
44-
"com.alibaba.fastjson2:fastjson2:2.0.43",
44+
"com.alibaba.fastjson2:fastjson2:2.0.59",
4545
"org.hamcrest:hamcrest-library:1.3",
4646
"io.netty:netty-all:4.1.65.Final",
4747
"org.assertj:assertj-core:3.22.0",
@@ -112,7 +112,7 @@ maven_install(
112112
"com.alipay.sofa:hessian:3.3.6",
113113
"io.netty:netty-tcnative-boringssl-static:2.0.48.Final",
114114
"org.mockito:mockito-junit-jupiter:4.11.0",
115-
"com.alibaba.fastjson2:fastjson2:2.0.43",
115+
"com.alibaba.fastjson2:fastjson2:2.0.59",
116116
"org.junit.jupiter:junit-jupiter-api:5.9.1",
117117
],
118118
fetch_sources = True,

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
<netty.tcnative.version>2.0.53.Final</netty.tcnative.version>
106106
<bcpkix-jdk18on.version>1.83</bcpkix-jdk18on.version>
107107
<fastjson.version>1.2.83</fastjson.version>
108-
<fastjson2.version>2.0.43</fastjson2.version>
108+
<fastjson2.version>2.0.59</fastjson2.version>
109109
<javassist.version>3.20.0-GA</javassist.version>
110110
<jna.version>4.2.2</jna.version>
111111
<commons-lang3.version>3.20.0</commons-lang3.version>

remoting/src/test/java/org/apache/rocketmq/remoting/protocol/DataVersionTest.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@
1717

1818
package org.apache.rocketmq.remoting.protocol;
1919

20-
import java.util.concurrent.atomic.AtomicLong;
21-
import org.junit.Assert;
20+
import com.alibaba.fastjson2.JSON;
2221
import org.junit.Test;
2322

23+
import java.util.concurrent.atomic.AtomicLong;
24+
25+
import static org.junit.Assert.assertEquals;
26+
import static org.junit.Assert.assertNotEquals;
27+
import static org.junit.Assert.assertNotNull;
28+
import static org.junit.Assert.assertTrue;
29+
2430
public class DataVersionTest {
2531

2632
@Test
2733
public void testEquals() {
2834
DataVersion dataVersion = new DataVersion();
2935
DataVersion other = new DataVersion();
3036
other.setTimestamp(dataVersion.getTimestamp());
31-
Assert.assertTrue(dataVersion.equals(other));
37+
assertEquals(dataVersion, other);
3238
}
3339

3440
@Test
@@ -37,7 +43,7 @@ public void testEquals_falseWhenCounterDifferent() {
3743
DataVersion other = new DataVersion();
3844
other.setCounter(new AtomicLong(1L));
3945
other.setTimestamp(dataVersion.getTimestamp());
40-
Assert.assertFalse(dataVersion.equals(other));
46+
assertNotEquals(dataVersion, other);
4147
}
4248

4349
@Test
@@ -46,7 +52,7 @@ public void testEquals_falseWhenCounterDifferent2() {
4652
DataVersion other = new DataVersion();
4753
other.setCounter(null);
4854
other.setTimestamp(dataVersion.getTimestamp());
49-
Assert.assertFalse(dataVersion.equals(other));
55+
assertNotEquals(dataVersion, other);
5056
}
5157

5258
@Test
@@ -55,7 +61,7 @@ public void testEquals_falseWhenCounterDifferent3() {
5561
dataVersion.setCounter(null);
5662
DataVersion other = new DataVersion();
5763
other.setTimestamp(dataVersion.getTimestamp());
58-
Assert.assertFalse(dataVersion.equals(other));
64+
assertNotEquals(dataVersion, other);
5965
}
6066

6167
@Test
@@ -65,13 +71,25 @@ public void testEquals_trueWhenCountersBothNull() {
6571
DataVersion other = new DataVersion();
6672
other.setCounter(null);
6773
other.setTimestamp(dataVersion.getTimestamp());
68-
Assert.assertTrue(dataVersion.equals(other));
74+
assertEquals(dataVersion, other);
6975
}
7076

7177
@Test
7278
public void testEncode() {
7379
DataVersion dataVersion = new DataVersion();
74-
Assert.assertTrue(dataVersion.encode().length > 0);
75-
Assert.assertNotNull(dataVersion.toJson());
80+
assertTrue(dataVersion.encode().length > 0);
81+
assertNotNull(dataVersion.toJson());
82+
}
83+
84+
@Test
85+
public void testJsonSerializationAndDeserialization() {
86+
DataVersion expected = new DataVersion();
87+
expected.setCounter(new AtomicLong(Long.MAX_VALUE));
88+
expected.setTimestamp(expected.getTimestamp());
89+
String jsonStr = expected.toJson();
90+
assertNotNull(jsonStr);
91+
DataVersion actual = JSON.parseObject(jsonStr, DataVersion.class);
92+
assertNotNull(actual);
93+
assertEquals(expected.getTimestamp(), actual.getTimestamp());
7694
}
7795
}

0 commit comments

Comments
 (0)