mandrean opened a new issue, #3519:
URL: https://github.com/apache/fory/issues/3519

   ### Search before asking
   
   - [x] I had searched in the [issues](https://github.com/apache/fory/issues) 
and found no similar issues.
   
   
   ### Version
   
   `v0.16.0`
   
   Probably introduced via 
[2abe9e4d7cf37ed78d35054527e43688429f7fd8](https://github.com/apache/fory/commit/2abe9e4d7cf37ed78d35054527e43688429f7fd8)
 in `v0.13.0`, when `ConcurrentSkipListSetSerializer` was changed to extend 
`ConcurrentCollectionSerializer` and its copy path stopped preserving the 
comparator.
   
   ### Component(s)
   
   Java
   
   ### Minimal reproduce step
   
   This was uncovered while adding broader constructor coverage around 
[#3337](https://github.com/apache/fory/issues/3337) / 
[#3342](https://github.com/apache/fory/pull/3342) and 
[#3343](https://github.com/apache/fory/issues/3343) / 
[#3344](https://github.com/apache/fory/pull/3344), but the bug is specifically 
in the fory.copy(...) path for ConcurrentSkipListSet.
   
   A minimal reproducer is:
   
   ```java
   package org.apache.fory.serializer.collection;
   
   import static org.testng.Assert.assertEquals;
   import static org.testng.Assert.assertNotNull;
   
   import java.io.Serializable;
   import java.util.ArrayList;
   import java.util.Arrays;
   import java.util.Comparator;
   import java.util.concurrent.ConcurrentSkipListSet;
   import org.apache.fory.Fory;
   import org.apache.fory.config.Language;
   import org.testng.annotations.Test;
   
   public class ConcurrentSkipListSetCopyComparatorReproTest {
     private static final class LengthThenNaturalComparator
         implements Comparator<String>, Serializable {
       @Override
       public int compare(String left, String right) {
         int delta = left.length() - right.length();
         return delta != 0 ? delta : left.compareTo(right);
       }
     }
   
     @Test
     public void testConcurrentSkipListSetCopyPreservesComparator() {
       Fory fory =
           Fory.builder()
               .withLanguage(Language.JAVA)
               .requireClassRegistration(false)
               .withRefCopy(true)
               .build();
   
       ConcurrentSkipListSet<String> values =
           new ConcurrentSkipListSet<>(new LengthThenNaturalComparator());
       values.addAll(Arrays.asList("bbb", "a", "cc"));
   
       ConcurrentSkipListSet<String> copy = fory.copy(values);
   
       assertNotNull(copy.comparator());
       assertEquals(new ArrayList<>(copy), Arrays.asList("a", "cc", "bbb"));
     }
   }
   ```
   
   ### What did you expect to see?
   
   `fory.copy(...)` should preserve the `ConcurrentSkipListSet` comparator, 
just like the deserialize path does, so the copied set keeps the same ordering 
semantics as the original.
   
   ### What did you see instead?
   
   The copy loses the comparator and falls back to natural ordering.
   
   Typical symptoms are:
   
   ```
   copy.comparator() == null
   and iteration order becomes:
   ```
   
   ```
   [a, bbb, cc]
   ```
   
   instead of the comparator-defined order:
   ```
   [a, cc, bbb]
   ```
   
   ### Anything Else?
   
   - This appears to affect the copy path only. The deserialize path already 
reads and applies the comparator in 
`ConcurrentSkipListSetSerializer.newCollection(MemoryBuffer)`.
   - This is easy to miss because `Set.equals(...)` still passes even when 
ordering semantics are lost.
   
   ### 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]


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

Reply via email to