This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new 8d5cc23c2 fix(java): crash when map only contains null value (#2444)
8d5cc23c2 is described below
commit 8d5cc23c2c203b21cfd77dc25fbada6ebcaa865c
Author: Leo <[email protected]>
AuthorDate: Fri Aug 8 17:36:50 2025 +0800
fix(java): crash when map only contains null value (#2444)
## What does this PR do?
<!-- Describe the purpose of this PR. -->
## Related issues
- #2441
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fory/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.
-->
---------
Co-authored-by: loushaokun <[email protected]>
Co-authored-by: Shawn Yang <[email protected]>
---
.../collection/AbstractMapSerializer.java | 2 +-
.../fory/serializer/CodegenSerializerTest.java | 59 ++++++++++++++++++++++
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git
a/java/fory-core/src/main/java/org/apache/fory/serializer/collection/AbstractMapSerializer.java
b/java/fory-core/src/main/java/org/apache/fory/serializer/collection/AbstractMapSerializer.java
index 321707b9d..c3866bf88 100644
---
a/java/fory-core/src/main/java/org/apache/fory/serializer/collection/AbstractMapSerializer.java
+++
b/java/fory-core/src/main/java/org/apache/fory/serializer/collection/AbstractMapSerializer.java
@@ -788,7 +788,7 @@ public abstract class AbstractMapSerializer<T> extends
Serializer<T> {
} else {
readNullKeyChunk(buffer, map, chunkHeader, valueSerializer,
valueHasNull);
}
- if (size-- == 0) {
+ if (--size == 0) {
return 0;
} else {
chunkHeader = buffer.readUnsignedByte();
diff --git
a/java/fory-core/src/test/java/org/apache/fory/serializer/CodegenSerializerTest.java
b/java/fory-core/src/test/java/org/apache/fory/serializer/CodegenSerializerTest.java
index 6a274c25e..53af834c1 100644
---
a/java/fory-core/src/test/java/org/apache/fory/serializer/CodegenSerializerTest.java
+++
b/java/fory-core/src/test/java/org/apache/fory/serializer/CodegenSerializerTest.java
@@ -28,7 +28,13 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@@ -342,4 +348,57 @@ public class CodegenSerializerTest extends ForyTestBase {
// ColorEnum.Green.getClass is a static local class.
// see https://github.com/apache/fory/issues/1033
}
+
+ @Test
+ public void testSimpleCollectionSerialization() {
+ class A {
+ Map<String, Object> f1;
+ Map<String, Object> f2;
+ Set<String> f3;
+ Set<String> f4;
+ List<String> f5;
+ List<Object> f6;
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ A a = (A) o;
+ return f1.equals(a.f1)
+ && f2.equals(a.f2)
+ && f3.equals(a.f3)
+ && f4.equals(a.f4)
+ && f5.equals(a.f5)
+ && f6.equals(a.f6);
+ }
+ }
+ A a = new A();
+ a.f1 = new HashMap<>();
+ a.f1.put("a", 1);
+ a.f1.put("你好", "str");
+
+ a.f2 = new LinkedHashMap<>();
+ a.f2.put("a", null);
+ a.f2.put("b", null);
+
+ a.f3 = new HashSet<>();
+ a.f3.add("你好");
+ a.f3.add("b");
+
+ a.f4 = new HashSet<>();
+ a.f4.add(null);
+ a.f4.add(null);
+
+ a.f5 = new ArrayList<>();
+ a.f5.add("你好");
+ a.f5.add("b");
+
+ a.f6 = new LinkedList<>();
+ a.f6.add(null);
+ a.f6.add(null);
+
+ Fory fory =
builder().requireClassRegistration(false).withCodegen(true).build();
+ A o = serDe(fory, a);
+ assertEquals(a, o);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]