Permalink
Browse files

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.
  • Loading branch information...
1 parent 6537d79 commit c049d66c54c4f255bc0de70b2fd4ec559df7ebcd @ViniciusMiana ViniciusMiana committed Feb 8, 2013
Showing with 16 additions and 0 deletions.
  1. +2 −0 src/library/scala/runtime/BoxedUnit.java
  2. +14 −0 test/files/run/t6935.scala
@@ -17,6 +17,8 @@
public final static BoxedUnit UNIT = new BoxedUnit();
public final static Class<Void> TYPE = java.lang.Void.TYPE;
+
+ private Object readResolve() { return UNIT; }
private BoxedUnit() { }
View
@@ -0,0 +1,14 @@
+object Test {
+
+ def main(args: Array[String]): Unit = {
+ import java.io._
+ val bytes = new ByteArrayOutputStream()
+ val out = new ObjectOutputStream(bytes)
+ out.writeObject(())
+ out.close()
+ val buf = bytes.toByteArray
+ val in = new ObjectInputStream(new ByteArrayInputStream(buf))
+ val unit = in.readObject()
+ assert(unit == ())
+ }
+}

0 comments on commit c049d66

Please sign in to comment.