-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
17.0.6, 20
submitter report:
====
came across a strange problem when serialising and deserialising records.
The application seems to hang. Consider the following example.
---
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.Serializable;
import java.util.List;
public class Example {
record Moon(String name) {}
record Planet(String name, List<Moon> moons) implements Serializable {}
public static void main(final String[] args) throws IOException, ClassNotFoundException {
try (PipedInputStream pipe = new PipedInputStream();
ObjectOutputStream out = new ObjectOutputStream(new PipedOutputStream(pipe));
ObjectInputStream in = new ObjectInputStream(pipe)) {
Planet earth = new Planet("Terra", List.of(new Moon("Luna")));
out.writeObject(earth);
out.flush();
Object o = in.readObject();
System.out.println(o);
}
}
}
---
The Moon record does not implement Serializable on purpose. Here I was
expecting an exception to be thrown, but instead the program hangs. If the
Moon record implements Serializable then the program works well.
Am I doing something wrong?
====
====
came across a strange problem when serialising and deserialising records.
The application seems to hang. Consider the following example.
---
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.Serializable;
import java.util.List;
public class Example {
record Moon(String name) {}
record Planet(String name, List<Moon> moons) implements Serializable {}
public static void main(final String[] args) throws IOException, ClassNotFoundException {
try (PipedInputStream pipe = new PipedInputStream();
ObjectOutputStream out = new ObjectOutputStream(new PipedOutputStream(pipe));
ObjectInputStream in = new ObjectInputStream(pipe)) {
Planet earth = new Planet("Terra", List.of(new Moon("Luna")));
out.writeObject(earth);
out.flush();
Object o = in.readObject();
System.out.println(o);
}
}
}
---
The Moon record does not implement Serializable on purpose. Here I was
expecting an exception to be thrown, but instead the program hangs. If the
Moon record implements Serializable then the program works well.
Am I doing something wrong?
====