From 71777cc9ff27786d74bda55a00ab477a4e53efb5 Mon Sep 17 00:00:00 2001 From: Rex Kerr Date: Tue, 31 Mar 2015 01:14:31 -0700 Subject: 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. --- .../concurrent/duration/SerializationTest.scala | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/junit/scala/concurrent/duration/SerializationTest.scala (limited to 'test') 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))) + } +} -- cgit v1.2.3