-
Notifications
You must be signed in to change notification settings - Fork 381
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Search before asking
- I had searched in the issues and found no similar issues.
Version
OS: macOS 26.1
Fory: 0.13.1
Java : java 21.0.8 2025-07-15 LTS
Component(s)
Java
Minimal reproduce step
/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2025 Apple Inc.
*/
import org.apache.fory.Fory;
import org.apache.fory.config.Language;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
public class CopyOnWriteArraySetTest {
public static void main(String[] args) {
Fory fory = Fory.builder()
.withLanguage(Language.JAVA)
.requireClassRegistration(false)
.build();
Set<String> set = new CopyOnWriteArraySet<>();
set.add("Value1");
set.add("Value2");
byte[] serialized = fory.serialize(set);
CopyOnWriteArraySet deserialised = fory.deserialize(serialized, CopyOnWriteArraySet.class);
System.out.println("deserialised=" + deserialised);
}
}
What did you expect to see?
Fory should be able to serialize java.util.concurrent.CopyOnWriteArraySet objects.
What did you see instead?
Serialization fails with a ClassCastException.
View full stack trace
Exception in thread "main" 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')
at org.apache.fory.Fory.processSerializationError(Fory.java:362)
at org.apache.fory.Fory.serialize(Fory.java:331)
at org.apache.fory.Fory.serialize(Fory.java:278)
at com.fory_tests.CopyOnWriteArraySetTest.main(CopyOnWriteArraySetTest.java:19)
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.builder.CopyOnWriteArraySetForyCodec_0.writeFields$(CopyOnWriteArraySetForyCodec_0.java:113)
at org.apache.fory.builder.CopyOnWriteArraySetForyCodec_0.write(CopyOnWriteArraySetForyCodec_0.java:224)
at org.apache.fory.serializer.collection.CollectionSerializers$DefaultJavaCollectionSerializer.write(CollectionSerializers.java:729)
at org.apache.fory.Fory.writeData(Fory.java:654)
at org.apache.fory.Fory.write(Fory.java:405)
at org.apache.fory.Fory.serialize(Fory.java:325)
Anything Else?
There seems to be a more fundamental issue with CopyOnWriteArrayListSerializer and how it works with codegen. For any object which has a CopyOnWriteArrayList field (like CopyOnWriteArraySet), serialization fails with the same error because the generated codec attempts to cast CollectionSnapshot to List.
Are you willing to submit a PR?
- I'm willing to submit a PR!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working