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

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 29a8cada91 [common] Fix double position advance in 
DataOutputSerializer.writeBytes (#9520)
29a8cada91 is described below

commit 29a8cada91a51070793be7f44e9d362afc66f93e
Author: YangJie <[email protected]>
AuthorDate: Wed Sep 2 02:41:02 2026 -0400

    [common] Fix double position advance in DataOutputSerializer.writeBytes 
(#9520)
---
 .../org/apache/paimon/io/DataOutputSerializer.java |  1 -
 .../apache/paimon/io/DataOutputSerializerTest.java | 56 ++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git 
a/paimon-common/src/main/java/org/apache/paimon/io/DataOutputSerializer.java 
b/paimon-common/src/main/java/org/apache/paimon/io/DataOutputSerializer.java
index 33f2a8f0bf..ee87cdbedb 100644
--- a/paimon-common/src/main/java/org/apache/paimon/io/DataOutputSerializer.java
+++ b/paimon-common/src/main/java/org/apache/paimon/io/DataOutputSerializer.java
@@ -153,7 +153,6 @@ public class DataOutputSerializer implements 
DataOutputView, MemorySegmentWritab
         for (int i = 0; i < sLen; i++) {
             writeByte(s.charAt(i));
         }
-        this.position += sLen;
     }
 
     @Override
diff --git 
a/paimon-common/src/test/java/org/apache/paimon/io/DataOutputSerializerTest.java
 
b/paimon-common/src/test/java/org/apache/paimon/io/DataOutputSerializerTest.java
new file mode 100644
index 0000000000..ac6d99573c
--- /dev/null
+++ 
b/paimon-common/src/test/java/org/apache/paimon/io/DataOutputSerializerTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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 org.apache.paimon.io;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Test for {@link DataOutputSerializer}. */
+public class DataOutputSerializerTest {
+
+    @Test
+    public void testWriteBytesAdvancesPositionOnce() throws IOException {
+        DataOutputSerializer out = new DataOutputSerializer(16);
+        out.writeBytes("abc");
+
+        assertThat(out.length()).isEqualTo(3);
+        assertThat(out.getCopyOfBuffer()).containsExactly('a', 'b', 'c');
+    }
+
+    @Test
+    public void testWriteBytesLeavesTheNextWriteInPlace() throws IOException {
+        DataOutputSerializer out = new DataOutputSerializer(16);
+        out.writeBytes("abc");
+        out.writeInt(42);
+
+        // "abc" and then 42 as a big-endian int, with no gap of untouched 
bytes in between.
+        assertThat(out.getCopyOfBuffer()).containsExactly('a', 'b', 'c', 0, 0, 
0, 42);
+    }
+
+    @Test
+    public void testWriteBytesAcrossAResize() throws IOException {
+        DataOutputSerializer out = new DataOutputSerializer(2);
+        out.writeBytes("abcdef");
+
+        assertThat(out.getCopyOfBuffer()).containsExactly('a', 'b', 'c', 'd', 
'e', 'f');
+    }
+}

Reply via email to