summaryrefslogtreecommitdiff
path: root/src/library
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 /src/library
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 'src/library')
-rw-r--r--src/library/scala/concurrent/duration/Duration.scala5
1 files changed, 4 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