NightOwl888 commented on PR #1089:
URL: https://github.com/apache/lucenenet/pull/1089#issuecomment-2585170593

   It appears that there is a difference between the default when using:
   
   - `StandardCharsets.UTF_8`
   - `StandardCharsets.UTF_8.newDecoder()`
   
   The default behavior of the latter is `CodingErrorAction.REPORT`, but the 
same is not true when using the former (which is how Lucene normally passes it 
to other APIs).
   
   ```java
     @Test
     public void testDefaultUTF8DecoderWithInvalidBytes() {
         // Define a mix of valid and invalid UTF-8 bytes
         byte[] testBytes = {
                 (byte) 0xE2, (byte) 0x82, (byte) 0xAC, // Valid UTF-8 for €
                 (byte) 0xC3, (byte) 0xA9,             // Valid UTF-8 for é
                 (byte) 0xFF,                          // Invalid byte
                 (byte) 0x41,                          // Valid ASCII for 'A'
                 (byte) 0x80,                          // Invalid byte
                 (byte) 0xF0, (byte) 0x9F, (byte) 0x92, (byte) 0x96 // Valid 
UTF-8 for 💖
         };
   
         // Decode the bytes using the default UTF-8 behavior
         String decodedString = new String(testBytes, StandardCharsets.UTF_8);
   
         // Print each character and its code point
         System.out.println("Decoded String Code Points: ");
         for (int i = 0; i < decodedString.length(); i++) {
             System.out.printf("Character at position %d: %d%n", i, (int) 
decodedString.charAt(i));
         }
         
         // Verify the decoded string (replacement character appears at invalid 
bytes)
         assertEquals("€é\uFFFDA\uFFFD💖", decodedString);
     }
   ```


-- 
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: dev-unsubscr...@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to