This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch releases-0.10
in repository https://gitbox.apache.org/repos/asf/fury.git

commit 924743c17d2bf142f21970b367f44db9c97d0d9a
Author: Shawn Yang <[email protected]>
AuthorDate: Thu Feb 6 15:26:10 2025 +0800

    fix(java): fix duplicate entry write at max chunk size bound (#2040)
    
    ## What does this PR do?
    
     fix duplicate entry write at max chunk size bound
    ## Related issues
    
    #2025
    #2027
    
    ## 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.
    -->
---
 .../org/apache/fury/builder/BaseObjectCodecBuilder.java    |  4 ++--
 .../fury/serializer/collection/AbstractMapSerializer.java  | 14 ++++++++------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git 
a/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
 
b/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
index 279f6798..ae044628 100644
--- 
a/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
+++ 
b/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
@@ -1337,7 +1337,6 @@ public abstract class BaseObjectCodecBuilder extends 
CodecBuilder {
                   writeKey,
                   writeValue,
                   new Assign(chunkSize, add(chunkSize, ofInt(1))),
-                  new If(eq(chunkSize, ofInt(MAX_CHUNK_SIZE)), new Break()),
                   new If(
                       inlineInvoke(iterator, "hasNext", 
PRIMITIVE_BOOLEAN_TYPE),
                       new ListExpression(
@@ -1348,7 +1347,8 @@ public abstract class BaseObjectCodecBuilder extends 
CodecBuilder {
                               key,
                               tryInlineCast(inlineInvoke(entry, "getKey", 
OBJECT_TYPE), keyType)),
                           new Assign(value, invokeInline(entry, "getValue", 
valueType))),
-                      list(new Assign(entry, new Literal(null, 
MAP_ENTRY_TYPE)), new Break())));
+                      list(new Assign(entry, new Literal(null, 
MAP_ENTRY_TYPE)), new Break())),
+                  new If(eq(chunkSize, ofInt(MAX_CHUNK_SIZE)), new Break()));
             });
     expressions.add(writeLoop, new Invoke(buffer, "putByte", chunkSizeOffset, 
chunkSize));
     if (!inline) {
diff --git 
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java
 
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java
index 037beeba..274f36b7 100644
--- 
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java
+++ 
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java
@@ -315,9 +315,7 @@ public abstract class AbstractMapSerializer<T> extends 
Serializer<T> {
         valueSerializer.write(buffer, value);
       }
       // noinspection Duplicates
-      if (++chunkSize == MAX_CHUNK_SIZE) {
-        break;
-      }
+      ++chunkSize;
       if (iterator.hasNext()) {
         entry = iterator.next();
         key = entry.getKey();
@@ -326,6 +324,9 @@ public abstract class AbstractMapSerializer<T> extends 
Serializer<T> {
         entry = null;
         break;
       }
+      if (chunkSize == MAX_CHUNK_SIZE) {
+        break;
+      }
     }
     buffer.putByte(chunkSizeOffset, (byte) chunkSize);
     return entry;
@@ -433,10 +434,8 @@ public abstract class AbstractMapSerializer<T> extends 
Serializer<T> {
         fury.incDepth(-1);
       }
       generics.popGenericType();
+      ++chunkSize;
       // noinspection Duplicates
-      if (++chunkSize == MAX_CHUNK_SIZE) {
-        break;
-      }
       if (iterator.hasNext()) {
         entry = iterator.next();
         key = entry.getKey();
@@ -445,6 +444,9 @@ public abstract class AbstractMapSerializer<T> extends 
Serializer<T> {
         entry = null;
         break;
       }
+      if (chunkSize == MAX_CHUNK_SIZE) {
+        break;
+      }
     }
     buffer.putByte(chunkSizeOffset, (byte) chunkSize);
     return entry;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to