[sent to both email list given it's not clear if it's an implementation issue 
or a spec issue]

There is a nice video of how the serialization of records works recently on 
inside.java
https://inside.java/2021/02/23/records-met-serialization/

In the video, Julia explains that the de-serialization works from bottom-up, so 
what if the record instances are a linked list ...
answer: a stack overflow.

Here is a small reproducer.

import static java.util.stream.IntStream.range;

public class RecordSerializationFailure {
  record Link(Object value, Link next) implements Serializable {}

  public static void main(String[] args) throws IOException, 
ClassNotFoundException {
    var link = range(0, 1_000_000)
        .boxed()
        .<Link>reduce(null, (next, i) -> new Link(i, next), (_1, _2) -> null);

    var path = Path.of("serial.data");
    try(var output = Files.newOutputStream(path);
        var oos = new ObjectOutputStream(output)) {
      oos.writeObject(link);
    }

    Link result;
    try(var input = Files.newInputStream(path);
        var ois = new ObjectInputStream(input)) {
      result = (Link) ois.readObject();
    }

    System.out.println(link.equals(result));
  }
}

Should this be fixed or not ?

regards,
RĂ©mi

Reply via email to