summaryrefslogtreecommitdiff
path: root/test/junit/scala/concurrent
diff options
context:
space:
mode:
authorRex Kerr <ichoran@gmail.com>2015-03-31 01:14:31 -0700
committerRex Kerr <ichoran@gmail.com>2015-03-31 15:37:40 -0700
commit71777cc9ff27786d74bda55a00ab477a4e53efb5 (patch)
treeaaa501960c857cab3f466adfed9038a1102b674a /test/junit/scala/concurrent
parent32f520f3ed78ecde390dc7b1b48d3130e412a9dc (diff)
downloadscala-71777cc9ff27786d74bda55a00ab477a4e53efb5.tar.gz
scala-71777cc9ff27786d74bda55a00ab477a4e53efb5.tar.bz2
scala-71777cc9ff27786d74bda55a00ab477a4e53efb5.zip
SI-9197 Duration.Inf not a singleton when deserialized
Made `Duration.Undefined`, `.Inf`, and `.MinusInf` all give back the singleton instance instead of creating a new copy by overriding readResolve. This override can be (and is) private, which at least on Sun's JDK8 doesn't mess with the auto-generated SerialVersionUIDs. Thus, the patch should make things strictly better: if you're on 2.11.7+ on JVMs which pick the same SerialVersionUIDs, you can recover singletons. Everywhere else you were already in trouble anyway.
Diffstat (limited to 'test/junit/scala/concurrent')
-rw-r--r--test/junit/scala/concurrent/duration/SerializationTest.scala24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/junit/scala/concurrent/duration/SerializationTest.scala b/test/junit/scala/concurrent/duration/SerializationTest.scala
new file mode 100644
index 0000000000..af90a10984
--- /dev/null
+++ b/test/junit/scala/concurrent/duration/SerializationTest.scala
@@ -0,0 +1,24 @@
+package scala.concurrent.duration
+
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.junit.Test
+
+
+@RunWith(classOf[JUnit4])
+class SerializationTest {
+ @Test
+ def test_SI9197 {
+ def ser(a: AnyRef): Array[Byte] = {
+ val bais = new java.io.ByteArrayOutputStream
+ (new java.io.ObjectOutputStream(bais)).writeObject(a)
+ bais.toByteArray
+ }
+ def des(ab: Array[Byte]): AnyRef =
+ (new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(ab))).readObject
+
+ assert(Duration.Undefined eq des(ser(Duration.Undefined)))
+ assert(Duration.Inf eq des(ser(Duration.Inf)))
+ assert(Duration.MinusInf eq des(ser(Duration.MinusInf)))
+ }
+}