apache / fury

A blazingly fast multi-language serialization framework powered by JIT and zero-copy.
https://fury.apache.org/
Apache License 2.0
3.11k stars 248 forks source link

[Java] ReplaceResolveSerializer circular references copy bug #1943

Open zhaommmmomo opened 1 week ago

zhaommmmomo commented 1 week ago

Search before asking

Version

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

Component(s)

Java

Minimal reproduce step

@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

Anything Else?

No response

Are you willing to submit a PR?