chaokunyang commented on code in PR #2999:
URL: https://github.com/apache/fory/pull/2999#discussion_r2596976329
##########
java/fory-core/src/main/java/org/apache/fory/serializer/collection/CollectionSerializer.java:
##########
@@ -61,7 +61,11 @@ public T copy(T originCollection) {
if (needToCopyRef) {
fory.reference(originCollection, newCollection);
}
- copyElements(originCollection, newCollection);
+ onCollectionCopy(originCollection, newCollection);
return (T) newCollection;
}
+
+ protected void onCollectionCopy(Collection originCollection, Collection
newCollection) {
Review Comment:
How about:
```java
public CopyOnWriteArrayList copy(T originCollection) {
CopyOnWriteArrayList newCollection = new CopyOnWriteArrayList();
if (needToCopyRef) {
fory.reference(originCollection, newCollection);
}
List copiedList = new ArrayList<>(originCollection.size());
copyElements(originCollection, copiedList);
newCollection.addAll(copiedList);
return newCollection;
}
```
We can't use `newCollection` API, it return a stub collection, which will
make wrong reference tracking if we have circualr references.
--
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]