apache / apache/fory

[Java] ReplaceResolveSerializer circular references copy bug

Open
#1,943 1 comment 0 reactions 1 assignee Claimed by @zhaommmmomo View on GitHub
bug
Dominant language
Java
Stars
4.5k
Forks
443
Avg merge
5h 59m
Merged PRs (30d)
77

Description

### Search before asking

- [X] I had searched in the [issues](https://github.com/apache/fury/issues) and found no similar issues.

### Version

fury 0.10.0-SNAPSHOT
https://github.com/apache/fury/pull/1925

### Component(s)

Java

### Minimal reproduce step

```java
@Test
public void test() {
Fury fury = Fury.builder().withRefCopy(true).withLanguage(Language.JAVA).build();
fury.registerSerializer(Tmp.class, ReplaceResolveSerializer.class);
Tmp a = new Tmp();
Tmp b = new Tmp();
a.name = "a";
a.ref = b;
b.name = "b";
b.ref = a;
Tmp copy = fury.copy(a);
assertNotSame(copy, a);
}

public static class Tmp implements Serializable {
public Object ref;
public String name;

private Object writeReplace() {
return ref;
}

private Object readResolve() {
return ref;
}
}
```

### What did you expect to see?

The copied object should not have the same address as the original object.

### What did you see instead?

The copied object has the same address as the original object.
![image](https://github.com/user-attachments/assets/89a3b0ac-2431-4b44-8c91-1ed05acc03a3)

### Anything Else?

_No response_

### Are you willing to submit a PR?

- [X] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.