LuciferYang opened a new issue, #9519:
URL: https://github.com/apache/paimon/issues/9519

   ### Search before asking
   
   - [x] I searched in the [issues](https://github.com/apache/paimon/issues) 
and found nothing similar.
   
   ### Paimon version
   
   master, `9c7deebbd` (2.1-SNAPSHOT)
   
   ### Compute Engine
   
   Java API. `DataOutputSerializer` implements `DataOutputView`, which extends 
`java.io.DataOutput`.
   
   ### Minimal reproduce step
   
   `writeBytes(String)` writes each byte through `writeByte`, which goes to 
`write(int)`:
   
   ```java
   public void write(int b) throws IOException {
       if (this.position >= this.buffer.length) {
           resize(1);
       }
       this.buffer[this.position++] = (byte) (b & 0xff);
   }
   ```
   
   so the position is already advanced per byte. The method then advanced it 
again by the string length:
   
   ```java
   for (int i = 0; i < sLen; i++) {
       writeByte(s.charAt(i));
   }
   this.position += sLen;
   ```
   
   ```java
   DataOutputSerializer out = new DataOutputSerializer(16);
   out.writeBytes("abc");
   out.length();            // 6, should be 3
   out.writeInt(42);
   out.length();            // 10, and bytes 3..5 were never written
   ```
   
   ### What doesn't meet your expectations?
   
   After `writeBytes`, `length()` reports twice the bytes written and every 
later write lands past a gap of untouched buffer, so the serialized output is 
longer than the data and carries whatever was in the array. The sibling 
`writeChars(String)` has the same shape, a `resize` followed by a loop of 
`writeChar`, and never had the extra advance, which is the intended form.
   
   Nothing in the repository calls this overload, so no Paimon code path is 
affected today. It is reachable for anyone holding a `DataOutputView` or 
`DataOutput`, which is the contract the class implements.
   
   ### Anything else?
   
   I audited the rest of the class: `write(byte[], int, int)`, 
`write(MemorySegment, int, int)`, `writeChar`, `writeShort`, `writeInt`, 
`writeLong`, `writeUTF`, `skipBytesToWrite` and `write(DataInputView, int)` all 
advance the position by exactly the bytes they wrote. `writeBytes` is the only 
one that does not.
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to