Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.13.0: mutable.HashSet.addAll processes parameter twice #11601

Open
miteshaghera opened this issue Jul 2, 2019 · 1 comment

Comments

Projects
None yet
5 participants
@miteshaghera
Copy link

commented Jul 2, 2019

addAll method of mutable.HashSet will process parameter twice if it's not a mutable.HashSet or immutable.HashSet. It potentially can cause duplicate elements in collection.

Please refer following testing code.

import java.util
import scala.jdk.CollectionConverters._

object HashSet {
  def main(args: Array[String]): Unit = {
    val jhs = new util.HashSet[Obj]()
    jhs.add(new Obj("A"))
    jhs.add(new Obj("B"))
    val shs = jhs.asScala.map(x => new Obj2(x.f))
    println("java set: " + jhs.size)
    println("scala set: " + shs.size)
  }
}

class Obj(val f:String) {
}

class Obj2(val f:String) {
}

It will not cause a problem if proper hashCode and equals are present in Obj2.

@sjrd

This comment has been minimized.

Copy link
Member

commented Jul 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.