vybhavjs opened a new pull request, #3079:
URL: https://github.com/apache/fory/pull/3079

   ## Why?
   
   Fory doesn't currently support serialization of any object that has a 
`CopyOnWriteArrayList` field with codegen, because the generated code attempts 
to cast `CollectionSnapshot` to `List`, throwing the following exception :
   
   ```
   org.apache.fory.exception.SerializationException: 
java.lang.ClassCastException: 
   class org.apache.fory.collection.CollectionSnapshot cannot be cast to class 
java.util.List 
   (org.apache.fory.collection.CollectionSnapshot is in unnamed module of 
loader 'app'; 
   java.util.List is in module java.base of loader 'bootstrap')
   
   
org.apache.fory.serializer.collection.CollectionSerializersTest.testCopyOnWriteArrayListNested(CollectionSerializersTest.java:407)
   Caused by: java.lang.ClassCastException: class 
org.apache.fory.collection.CollectionSnapshot cannot be cast to class 
java.util.List 
   (org.apache.fory.collection.CollectionSnapshot is in unnamed module of 
loader 'app'; 
   java.util.List is in module java.base of loader 'bootstrap')
        at 
org.apache.fory.serializer.collection.CollectionSerializersTest_NestedCopyOnWriteArrayListForyCodec_0.writeFields$(CollectionSerializersTest_NestedCopyOnWriteArrayListForyCodec_0.java:63)
        at 
org.apache.fory.serializer.collection.CollectionSerializersTest_NestedCopyOnWriteArrayListForyCodec_0.write(CollectionSerializersTest_NestedCopyOnWriteArrayListForyCodec_0.java:130)
   ```
   
   This is the relevant code from the the generated codec that attempts the 
invalid class cast.
   
   ```
   CollectionLikeSerializer collectionLikeSerializer = 
this.writeCollectionClassInfo(list0, memoryBuffer1);
   if (collectionLikeSerializer.supportCodegenHook()) {
       java.util.List list1 = 
(java.util.List)collectionLikeSerializer.onCollectionWrite(memoryBuffer1, 
list0);
   ```
   
   ## What does this PR do?
   
   * feat: Define `ListSnapshot extends AbstractList` similar to existing 
`CollectionSnapshot` and `MapSnapshot`.
   * feat: Define `ConcurrentListSerializer`, similar to existing 
`ConcurrentCollectionSerializer` and `ConcurrentMapSerializer`
   * fix: Update `CopyOnWriteArrayListSerializer` to extend the new 
`ConcurrentListSerializer`
   * test: Add `ListSnapshotTest` to test `ListSnapshot` behaviour
   * test: Add test in `CollectionSerializersTest` to test nested 
CopyOnWriteArrayList serialization
   
   ## Related issues
   
   Fixes #2918.
   
   ## Does this PR introduce any user-facing change?
   
   <!--
   If any user-facing interface changes, please [open an 
issue](https://github.com/apache/fory/issues/new/choose) describing the need to 
do so and update the document if necessary.
   
   Delete section if not applicable.
   -->
   
   - [ ] 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.
   
   Delete section if not applicable.
   -->
   


-- 
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