Skip to content

JavaConversions.MapWrapper generates wrong hashCode eventually #5880

@scabug

Description

@scabug

scala.collection.JavaConversions.MapWrapper's entrySet method seems to generate a Set having wrong hashCode() implementation. The hashcode has the possibility of conflict.

I checked the problem with the following code:

import scala.collection.JavaConversions._

object App {
  def main(args:Array[String]) = {
    val jm:java.util.Map[String, String] = scala.collection.mutable.Map("a" -> "b", "b" -> "a")
    val es = jm.entrySet()
    val it = es.iterator
    println(it)
    while (it.hasNext) {
      val x = it.next()
      println("key=" + x.getKey + ", val=" + x.getValue)
      println("hashCode=" + x.##)
    }
  }
}

=========
output

scala.collection.JavaConversions$MapWrapper$$anon$1$$anon$5@6cb8
key=a, val=b
hashCode=195
key=b, val=a
hashCode=195

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions