Deserialization of a linked list of records

Remi Forax forax at
Fri Feb 26 22:06:49 UTC 2021

[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

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;

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)
        .<Link>reduce(null, (next, i) -> new Link(i, next), (_1, _2) -> null);

    var path = Path.of("");
    try(var output = Files.newOutputStream(path);
        var oos = new ObjectOutputStream(output)) {

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


Should this be fixed or not ?


More information about the amber-spec-experts mailing list