CollectionType#replaceElements may clear the original collection during merge

Description

During a merge, the CollectionType#replaceElements method calls clear on the target object:

But, in certain situations, the target is a PersistentSet wrapping the original collection, so when clear is called, the original collection gets cleared as well, so all the elements collections will be deleted.

The attached test case proves the issue.

To see the problem, add a breakpoint at this line:

And then, add another breakpoint in the replaceElements method of the CollectionType.

On the 8th call of that breakpoint, we get the following objects:

Now, the problem is that target is basically rapping the original collection:

And, for this reason, the collection will be deleted, even if it should have been merged with the new data:

Environment

None

Activity

Show:
Vlad Mihalcea
November 10, 2020, 10:51 AM

Do you think this could be related to ?

Fixed

Assignee

Christian Beikov

Reporter

Vlad Mihalcea

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major
Configure