Skip to content

Commit

Permalink
Merge pull request #9166 from regadas/2.12.x_serial_version
Browse files Browse the repository at this point in the history
Add missing @serialversionuid on collections
  • Loading branch information
lrytz committed Feb 18, 2021
2 parents 2ee5f6c + a5c4802 commit fcc5845
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions project/MimaFilters.scala
Expand Up @@ -25,6 +25,9 @@ object MimaFilters extends AutoPlugin {

// #9314 #9315 #9507 NewRedBlackTree is private[collection]
ProblemFilters.exclude[Problem]("scala.collection.immutable.NewRedBlackTree*"),

// #9166 add missing serialVersionUID
ProblemFilters.exclude[MissingFieldProblem]("*.serialVersionUID"),
)

override val buildSettings = Seq(
Expand Down
1 change: 1 addition & 0 deletions src/library/scala/collection/MapLike.scala
Expand Up @@ -172,6 +172,7 @@ self =>

/** The implementation class of the set returned by `keySet`.
*/
@SerialVersionUID(1589106351530299313L)
protected class DefaultKeySet extends AbstractSet[K] with Set[K] with Serializable {
def contains(key : K) = self.contains(key)
def iterator = keysIterator
Expand Down
1 change: 1 addition & 0 deletions src/library/scala/collection/SortedMapLike.scala
Expand Up @@ -36,6 +36,7 @@ self =>

override def keySet : SortedSet[A] = new DefaultKeySortedSet

@SerialVersionUID(-38666158592954763L)
protected class DefaultKeySortedSet extends super.DefaultKeySet with SortedSet[A] {
implicit def ordering = self.ordering
override def + (elem: A): SortedSet[A] = (SortedSet[A]() ++ this + elem)
Expand Down
19 changes: 19 additions & 0 deletions src/library/scala/collection/convert/Wrappers.scala
Expand Up @@ -27,6 +27,7 @@ private[collection] trait Wrappers {
override def isEmpty = underlying.isEmpty
}

@SerialVersionUID(7914730360012802566L)
case class IteratorWrapper[A](underlying: Iterator[A]) extends ju.Iterator[A] with ju.Enumeration[A] {
def hasNext = underlying.hasNext
def next() = underlying.next()
Expand All @@ -39,34 +40,41 @@ private[collection] trait Wrappers {
def asJava = new IteratorWrapper(underlying)
}

@SerialVersionUID(-2624079708378729299L)
case class JIteratorWrapper[A](underlying: ju.Iterator[A]) extends AbstractIterator[A] with Iterator[A] {
def hasNext = underlying.hasNext
def next() = underlying.next
}

@SerialVersionUID(1480199642890917878L)
case class JEnumerationWrapper[A](underlying: ju.Enumeration[A]) extends AbstractIterator[A] with Iterator[A] {
def hasNext = underlying.hasMoreElements
def next() = underlying.nextElement
}

@SerialVersionUID(8702516763061989735L)
case class IterableWrapper[A](underlying: Iterable[A]) extends ju.AbstractCollection[A] with IterableWrapperTrait[A] { }

@SerialVersionUID(4914368587801013118L)
case class JIterableWrapper[A](underlying: jl.Iterable[A]) extends AbstractIterable[A] with Iterable[A] {
def iterator = underlying.iterator
def newBuilder[B] = new mutable.ArrayBuffer[B]
}

@SerialVersionUID(-9156669203906593803L)
case class JCollectionWrapper[A](underlying: ju.Collection[A]) extends AbstractIterable[A] with Iterable[A] {
def iterator = underlying.iterator
override def size = underlying.size
override def isEmpty = underlying.isEmpty
def newBuilder[B] = new mutable.ArrayBuffer[B]
}

@SerialVersionUID(-2066086677605085135L)
case class SeqWrapper[A](underlying: Seq[A]) extends ju.AbstractList[A] with IterableWrapperTrait[A] {
def get(i: Int) = underlying(i)
}

@SerialVersionUID(-3277343097189933650L)
case class MutableSeqWrapper[A](underlying: mutable.Seq[A]) extends ju.AbstractList[A] with IterableWrapperTrait[A] {
def get(i: Int) = underlying(i)
override def set(i: Int, elem: A) = {
Expand All @@ -76,13 +84,15 @@ private[collection] trait Wrappers {
}
}

@SerialVersionUID(2065310383330290590L)
case class MutableBufferWrapper[A](underlying: mutable.Buffer[A]) extends ju.AbstractList[A] with IterableWrapperTrait[A] {
def get(i: Int) = underlying(i)
override def set(i: Int, elem: A) = { val p = underlying(i); underlying(i) = elem; p }
override def add(elem: A) = { underlying append elem; true }
override def remove(i: Int) = underlying remove i
}

@SerialVersionUID(-7340917072424655477L)
case class JListWrapper[A](underlying: ju.List[A]) extends mutable.AbstractBuffer[A] with mutable.Buffer[A] {
def length = underlying.size
override def isEmpty = underlying.isEmpty
Expand Down Expand Up @@ -132,6 +142,7 @@ private[collection] trait Wrappers {
}
}

@SerialVersionUID(-4801553198679985982L)
case class MutableSetWrapper[A](underlying: mutable.Set[A]) extends SetWrapper[A](underlying) {
override def add(elem: A) = {
val sz = underlying.size
Expand All @@ -144,6 +155,7 @@ private[collection] trait Wrappers {
override def clear() = underlying.clear()
}

@SerialVersionUID(-8813164664953372494L)
case class JSetWrapper[A](underlying: ju.Set[A]) extends mutable.AbstractSet[A] with mutable.Set[A] with mutable.SetLike[A, JSetWrapper[A]] {

override def size = underlying.size
Expand Down Expand Up @@ -240,6 +252,7 @@ private[collection] trait Wrappers {
}
}

@SerialVersionUID(8668425014051911127L)
case class MutableMapWrapper[A, B](underlying: mutable.Map[A, B]) extends MapWrapper[A, B](underlying) {
override def put(k: A, v: B) = underlying.put(k, v) match {
case Some(v1) => v1
Expand Down Expand Up @@ -300,10 +313,12 @@ private[collection] trait Wrappers {
* This includes `get`, as `java.util.Map`'s API does not allow for an
* atomic `get` when `null` values may be present.
*/
@SerialVersionUID(5258955232187049103L)
case class JMapWrapper[A, B](underlying : ju.Map[A, B]) extends mutable.AbstractMap[A, B] with JMapWrapperLike[A, B, JMapWrapper[A, B]] {
override def empty = JMapWrapper(new ju.HashMap[A, B])
}

@SerialVersionUID(3929791676502269860L)
class ConcurrentMapWrapper[A, B](override val underlying: concurrent.Map[A, B]) extends MutableMapWrapper[A, B](underlying) with juc.ConcurrentMap[A, B] {

override def putIfAbsent(k: A, v: B) = underlying.putIfAbsent(k, v) match {
Expand All @@ -330,6 +345,7 @@ private[collection] trait Wrappers {
* access is supported; multi-element operations such as maps and filters
* are not guaranteed to be atomic.
*/
@SerialVersionUID(-8245743033724996882L)
case class JConcurrentMapWrapper[A, B](underlying: juc.ConcurrentMap[A, B]) extends mutable.AbstractMap[A, B] with JMapWrapperLike[A, B, JConcurrentMapWrapper[A, B]] with concurrent.Map[A, B] {
override def get(k: A) = Option(underlying get k)

Expand All @@ -345,6 +361,7 @@ private[collection] trait Wrappers {
underlying.replace(k, oldvalue, newvalue)
}

@SerialVersionUID(942915481780293390L)
case class DictionaryWrapper[A, B](underlying: mutable.Map[A, B]) extends ju.Dictionary[A, B] {
def size: Int = underlying.size
def isEmpty: Boolean = underlying.isEmpty
Expand Down Expand Up @@ -372,6 +389,7 @@ private[collection] trait Wrappers {
}
}

@SerialVersionUID(-5214182838863307389L)
case class JDictionaryWrapper[A, B](underlying: ju.Dictionary[A, B]) extends mutable.AbstractMap[A, B] with mutable.Map[A, B] {
override def size: Int = underlying.size

Expand All @@ -391,6 +409,7 @@ private[collection] trait Wrappers {
override def clear() = underlying.clear()
}

@SerialVersionUID(1265445269473530406L)
case class JPropertiesWrapper(underlying: ju.Properties) extends mutable.AbstractMap[String, String]
with mutable.Map[String, String]
with mutable.MapLike[String, String, JPropertiesWrapper] {
Expand Down
2 changes: 2 additions & 0 deletions src/library/scala/collection/immutable/BitSet.scala
Expand Up @@ -123,6 +123,7 @@ object BitSet extends BitSetFactory[BitSet] {
else new BitSet1(elems - java.lang.Long.lowestOneBit(elems))
}

@SerialVersionUID(-860417644893387539L)
class BitSet2(val elems0: Long, elems1: Long) extends BitSet {
protected def nwords = 2
protected def word(idx: Int) = if (idx == 0) elems0 else if (idx == 1) elems1 else 0L
Expand Down Expand Up @@ -150,6 +151,7 @@ object BitSet extends BitSetFactory[BitSet] {
* implementation. Care needs to be taken not to modify the exposed
* array.
*/
@SerialVersionUID(807040099560956194L)
class BitSetN(val elems: Array[Long]) extends BitSet {
protected def nwords = elems.length
protected def word(idx: Int) = if (idx < nwords) elems(idx) else 0L
Expand Down
3 changes: 3 additions & 0 deletions src/library/scala/collection/immutable/HashMap.scala
Expand Up @@ -347,6 +347,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
}

@deprecatedInheritance("This class will be made final in a future release.", "2.12.2")
@SerialVersionUID(4549809275616486327L)
class HashMap1[A,+B](private[collection] val key: A, private[collection] val hash: Int, private[collection] val value: (B @uV), private[this] var kvOrNull: (A,B @uV)) extends HashMap[A,B] {
override def size = 1

Expand Down Expand Up @@ -436,6 +437,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
}
}

@SerialVersionUID(-1917647429457579983L)
private[collection] class HashMapCollision1[A, +B](private[collection] val hash: Int, val kvs: ListMap[A, B @uV])
extends HashMap[A, B @uV] {
// assert(kvs.size > 1)
Expand Down Expand Up @@ -551,6 +553,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
}

@deprecatedInheritance("This class will be made final in a future release.", "2.12.2")
@SerialVersionUID(834418348325321784L)
class HashTrieMap[A, +B](
private[HashMap] var bitmap0: Int,
private[HashMap] var elems0: Array[HashMap[A, B @uV]],
Expand Down
4 changes: 4 additions & 0 deletions src/library/scala/collection/immutable/HashSet.scala
Expand Up @@ -259,8 +259,10 @@ object HashSet extends ImmutableSetFactory[HashSet] {
/**
* Common superclass of HashSet1 and HashSetCollision1, which are the two possible leaves of the Trie
*/
@SerialVersionUID(-8788235040812980474L)
private[HashSet] sealed abstract class LeafHashSet[A](private[HashSet] final val hash: Int) extends HashSet[A]

@SerialVersionUID(7828248784025959392L)
class HashSet1[A](private[HashSet] val key: A, hash: Int) extends LeafHashSet[A](hash) {
override def size = 1

Expand Down Expand Up @@ -333,6 +335,7 @@ object HashSet extends ImmutableSetFactory[HashSet] {
override def foreach[U](f: A => U): Unit = f(key)
}

@SerialVersionUID(-4499898620567995040L)
private[immutable] class HashSetCollision1[A](hash: Int, val ks: ListSet[A], override val size: Int) extends LeafHashSet[A](hash) {

override protected def get0(key: A, hash: Int, level: Int): Boolean =
Expand Down Expand Up @@ -536,6 +539,7 @@ object HashSet extends ImmutableSetFactory[HashSet] {
* elems: [a,b]
* children: ---b----------------a-----------
*/
@SerialVersionUID(-1260675327783828535L)
class HashTrieSet[A](private[HashSet] var bitmap: Int, private[collection] var elems: Array[HashSet[A]], private[HashSet] var size0: Int)
extends HashSet[A] {
@inline override final def size = size0
Expand Down
3 changes: 3 additions & 0 deletions src/library/scala/collection/immutable/IntMap.scala
Expand Up @@ -64,6 +64,7 @@ object IntMap {
def apply[T](elems: (Int, T)*): IntMap[T] =
elems.foldLeft(empty[T])((x, y) => x.updated(y._1, y._2))

@SerialVersionUID(-9137650114085457282L)
private[immutable] case object Nil extends IntMap[Nothing] {
// Important! Without this equals method in place, an infinite
// loop from Map.equals => size => pattern-match-on-Nil => equals
Expand All @@ -76,11 +77,13 @@ object IntMap {
}
}

@SerialVersionUID(3302720273753906158L)
private[immutable] case class Tip[+T](key: Int, value: T) extends IntMap[T]{
def withValue[S](s: S) =
if (s.asInstanceOf[AnyRef] eq value.asInstanceOf[AnyRef]) this.asInstanceOf[IntMap.Tip[S]]
else IntMap.Tip(key, s)
}
@SerialVersionUID(-523093388545197183L)
private[immutable] case class Bin[+T](prefix: Int, mask: Int, left: IntMap[T], right: IntMap[T]) extends IntMap[T] {
def bin[S](left: IntMap[S], right: IntMap[S]): IntMap[S] = {
if ((this.left eq left) && (this.right eq right)) this.asInstanceOf[IntMap.Bin[S]]
Expand Down
3 changes: 3 additions & 0 deletions src/library/scala/collection/immutable/LongMap.scala
Expand Up @@ -62,6 +62,7 @@ object LongMap {
def apply[T](elems: (Long, T)*): LongMap[T] =
elems.foldLeft(empty[T])((x, y) => x.updated(y._1, y._2))

@SerialVersionUID(1224320979026293120L)
private[immutable] case object Nil extends LongMap[Nothing] {
// Important, don't remove this! See IntMap for explanation.
override def equals(that : Any) = that match {
Expand All @@ -71,11 +72,13 @@ object LongMap {
}
}

@SerialVersionUID(4938010434684160500L)
private[immutable] case class Tip[+T](key: Long, value: T) extends LongMap[T] {
def withValue[S](s: S) =
if (s.asInstanceOf[AnyRef] eq value.asInstanceOf[AnyRef]) this.asInstanceOf[LongMap.Tip[S]]
else LongMap.Tip(key, s)
}
@SerialVersionUID(2433491195925361636L)
private[immutable] case class Bin[+T](prefix: Long, mask: Long, left: LongMap[T], right: LongMap[T]) extends LongMap[T] {
def bin[S](left: LongMap[S], right: LongMap[S]): LongMap[S] = {
if ((this.left eq left) && (this.right eq right)) this.asInstanceOf[LongMap.Bin[S]]
Expand Down
1 change: 1 addition & 0 deletions src/library/scala/collection/immutable/Map.scala
Expand Up @@ -91,6 +91,7 @@ object Map extends ImmutableMapFactory[Map] {

def empty[K, V]: Map[K, V] = EmptyMap.asInstanceOf[Map[K, V]]

@SerialVersionUID(-7464981207502461188L)
class WithDefault[K, +V](underlying: Map[K, V], d: K => V) extends scala.collection.Map.WithDefault[K, V](underlying, d) with Map[K, V] {
override def empty = new WithDefault(underlying.empty, d)
override def updated[V1 >: V](key: K, value: V1): WithDefault[K, V1] = new WithDefault[K, V1](underlying.updated[V1](key, value), d)
Expand Down
3 changes: 3 additions & 0 deletions src/library/scala/collection/immutable/NumericRange.scala
Expand Up @@ -39,6 +39,7 @@ package immutable
* @define mayNotTerminateInf
* @define willNotTerminateInf
*/
@SerialVersionUID(-5580158174769432538L)
abstract class NumericRange[T]
(val start: T, val end: T, val step: T, val isInclusive: Boolean)
(implicit num: Integral[T])
Expand Down Expand Up @@ -365,6 +366,7 @@ object NumericRange {
}
}

@SerialVersionUID(-5986512874781685419L)
class Inclusive[T](start: T, end: T, step: T)(implicit num: Integral[T])
extends NumericRange(start, end, step, true) {
def copy(start: T, end: T, step: T): Inclusive[T] =
Expand All @@ -373,6 +375,7 @@ object NumericRange {
def exclusive: Exclusive[T] = NumericRange(start, end, step)
}

@SerialVersionUID(-7058074814271573640L)
class Exclusive[T](start: T, end: T, step: T)(implicit num: Integral[T])
extends NumericRange(start, end, step, false) {
def copy(start: T, end: T, step: T): Exclusive[T] =
Expand Down
1 change: 1 addition & 0 deletions src/library/scala/collection/immutable/Range.scala
Expand Up @@ -439,6 +439,7 @@ object Range {
def count(start: Int, end: Int, step: Int): Int =
count(start, end, step, isInclusive = false)

@SerialVersionUID(4237131469519710909L)
final class Inclusive(start: Int, end: Int, step: Int) extends Range(start, end, step) {
// override def par = new ParRange(this)
override def isInclusive = true
Expand Down
1 change: 1 addition & 0 deletions src/library/scala/collection/immutable/SortedMap.scala
Expand Up @@ -42,6 +42,7 @@ self =>
override def updated [B1 >: B](key: A, value: B1): SortedMap[A, B1] = this + ((key, value))
override def keySet: immutable.SortedSet[A] = new DefaultKeySortedSet

@SerialVersionUID(112809526508924148L)
protected class DefaultKeySortedSet extends super.DefaultKeySortedSet with immutable.SortedSet[A] {
override def + (elem: A): SortedSet[A] =
if (this(elem)) this
Expand Down

0 comments on commit fcc5845

Please sign in to comment.