diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2015-04-22 17:26:39 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2015-04-22 17:26:39 -0700 |
commit | d7aacbbd49b9524a2eb265fe8aa7634844bf57bb (patch) | |
tree | 160626eed3460275e9e896867b962b84a48aaa3d | |
parent | 8f99b5819449c01d89a918069029f7898c56e35a (diff) | |
parent | 71777cc9ff27786d74bda55a00ab477a4e53efb5 (diff) | |
download | scala-d7aacbbd49b9524a2eb265fe8aa7634844bf57bb.tar.gz scala-d7aacbbd49b9524a2eb265fe8aa7634844bf57bb.tar.bz2 scala-d7aacbbd49b9524a2eb265fe8aa7634844bf57bb.zip |
Merge pull request #4416 from Ichoran/issue/9197
SI-9197 Duration.Inf not a singleton when deserialized
-rw-r--r-- | src/library/scala/concurrent/duration/Duration.scala | 5 | ||||
-rw-r--r-- | test/junit/scala/concurrent/duration/SerializationTest.scala | 24 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/library/scala/concurrent/duration/Duration.scala b/src/library/scala/concurrent/duration/Duration.scala index 2eded9f060..182c2d172a 100644 --- a/src/library/scala/concurrent/duration/Duration.scala +++ b/src/library/scala/concurrent/duration/Duration.scala @@ -182,6 +182,7 @@ object Duration { def compare(other: Duration) = if (other eq this) 0 else 1 def unary_- : Duration = this def toUnit(unit: TimeUnit): Double = Double.NaN + private def readResolve(): AnyRef = Undefined // Instructs deserialization to use this same instance } sealed abstract class Infinite extends Duration { @@ -230,7 +231,7 @@ object Duration { * but itself. This value closely corresponds to Double.PositiveInfinity, * matching its semantics in arithmetic operations. */ - val Inf: Infinite = new Infinite { + val Inf: Infinite = new Infinite { override def toString = "Duration.Inf" def compare(other: Duration) = other match { case x if x eq Undefined => -1 // Undefined != Undefined @@ -239,6 +240,7 @@ object Duration { } def unary_- : Duration = MinusInf def toUnit(unit: TimeUnit): Double = Double.PositiveInfinity + private def readResolve(): AnyRef = Inf // Instructs deserialization to use this same instance } /** @@ -251,6 +253,7 @@ object Duration { def compare(other: Duration) = if (other eq this) 0 else -1 def unary_- : Duration = Inf def toUnit(unit: TimeUnit): Double = Double.NegativeInfinity + private def readResolve(): AnyRef = MinusInf // Instructs deserialization to use this same instance } // Java Factories 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))) + } +} |