Skip to content

Commit 3c1df17

Browse files
authored
fix(java): Fix the issue caused by not using readCompressedBytesString during deserialization when string compression is enabled. (#1991)
Fix the issue caused by not using readCompressedBytesString during deserialization when string compression is enabled. <!-- **Thanks for contributing to Fury.** **If this is your first time opening a PR on fury, you can refer to [CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).** Contribution Checklist - The **Apache Fury (incubating)** community has restrictions on the naming of pr titles. You can also find instructions in [CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md). - Fury has a strong focus on performance. If the PR you submit will have an impact on performance, please benchmark it first and provide the benchmark result here. --> ## What does this PR do? fix issue [#1984 ](#1984) <!-- Describe the purpose of this PR. --> ## Related issues <!-- Is there any related issue? Please attach here. - #xxxx0 - #xxxx1 - #xxxx2 --> ## Does this PR introduce any user-facing change? <!-- If any user-facing interface changes, please [open an issue](https://github.com/apache/fury/issues/new/choose) describing the need to do so and update the document if necessary. --> - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? ## Benchmark <!-- When the PR has an impact on performance (if you don't know whether the PR will have an impact on performance, you can submit the PR first, and if it will have impact on performance, the code reviewer will explain it), be sure to attach a benchmark data here. -->
1 parent 98efd72 commit 3c1df17

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

java/fury-core/src/main/java/org/apache/fury/serializer/StringSerializer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ public String readString(MemoryBuffer buffer) {
176176
public Expression readStringExpr(Expression strSerializer, Expression buffer) {
177177
if (isJava) {
178178
if (STRING_VALUE_FIELD_IS_BYTES) {
179-
return new Invoke(strSerializer, "readBytesString", STRING_TYPE, buffer);
179+
if (compressString) {
180+
return new Invoke(strSerializer, "readCompressedBytesString", STRING_TYPE, buffer);
181+
} else {
182+
return new Invoke(strSerializer, "readBytesString", STRING_TYPE, buffer);
183+
}
180184
} else {
181185
if (!STRING_VALUE_FIELD_IS_CHARS) {
182186
throw new UnsupportedOperationException();

java/fury-core/src/test/java/org/apache/fury/serializer/StringSerializerTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.concurrent.ArrayBlockingQueue;
3030
import java.util.concurrent.BlockingQueue;
3131
import java.util.concurrent.ConcurrentLinkedQueue;
32+
import lombok.Data;
3233
import org.apache.fury.Fury;
3334
import org.apache.fury.FuryTestBase;
3435
import org.apache.fury.collection.Tuple2;
@@ -160,6 +161,35 @@ public void testJavaStringSimple() {
160161
}
161162
}
162163

164+
@Data
165+
public static class Simple {
166+
private String str;
167+
168+
public Simple(String str) {
169+
this.str = str;
170+
}
171+
}
172+
173+
/** Test for <a href="https://github.com/apache/fury/issues/1984">#1984</a> */
174+
@Test
175+
public void testJavaCompressedString() {
176+
Fury fury =
177+
Fury.builder()
178+
.withStringCompressed(true)
179+
.withLanguage(Language.JAVA)
180+
.requireClassRegistration(false)
181+
.build();
182+
183+
Simple a =
184+
new Simple(
185+
"STG@ON DEMAND Solutions@GeoComputing Switch/ Hub@Digi Edgeport/216 – 16 port Serial Hub");
186+
187+
byte[] bytes = fury.serialize(a);
188+
189+
Simple b = (Simple) fury.deserialize(bytes);
190+
assertEquals(a, b);
191+
}
192+
163193
@Test(dataProvider = "stringCompress")
164194
public void testJavaString(boolean stringCompress) {
165195
Fury fury =

0 commit comments

Comments
 (0)