Skip to content

Commit c049d66

Browse files
committed
SI-6935 Added readResolve in BoxedUnit
When deserializing Unit, it would return an instance of Object, but not a Scala Unit. By adding readResolve, the deserialization of Unit will work.
1 parent 6537d79 commit c049d66

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/library/scala/runtime/BoxedUnit.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public final class BoxedUnit implements java.io.Serializable {
1717
public final static BoxedUnit UNIT = new BoxedUnit();
1818

1919
public final static Class<Void> TYPE = java.lang.Void.TYPE;
20+
21+
private Object readResolve() { return UNIT; }
2022

2123
private BoxedUnit() { }
2224

test/files/run/t6935.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Test {
2+
3+
def main(args: Array[String]): Unit = {
4+
import java.io._
5+
val bytes = new ByteArrayOutputStream()
6+
val out = new ObjectOutputStream(bytes)
7+
out.writeObject(())
8+
out.close()
9+
val buf = bytes.toByteArray
10+
val in = new ObjectInputStream(new ByteArrayInputStream(buf))
11+
val unit = in.readObject()
12+
assert(unit == ())
13+
}
14+
}

0 commit comments

Comments
 (0)