The GitHub Actions job "Publish Fory Java Snapshot" on fory.git/main has 
succeeded.
Run started by GitHub user chaokunyang (triggered by chaokunyang).

Head commit for run:
9a12400eeadb7ebc2d1ea3a132e77fec7f4768a9 / Vybhav Jayasankar 
<[email protected]>
fix(java): Fix CopyOnWriteArrayList field serialization (#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 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: Update `CollectionSnapshot` to extend `AbstractList` instead of
`AbstractCollection`, and implement `get(index)` method
* test: Add test in `CollectionSerializersTest` for serializing objects
with CopyOnWriteArrayList fields
* test: Add test in `CollectionSnapshotTest` for
`CollectionSnapshot.get(index)`

## Related issues

Fixes pending issues from #2918.

## Does this PR introduce any user-facing change?



- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?

## Benchmark

Report URL: https://github.com/apache/fory/actions/runs/20465902575

With regards,
GitHub Actions via GitBox


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

Reply via email to