Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-5880

JavaConversions.MapWrapper generates wrong hashCode eventually

    Details

    • Type: Bug
    • Status: CLOSED
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.2
    • Fix Version/s: Scala 2.10.0-M3
    • Component/s: None
    • Labels:
      None
    • Environment:

      Darwin Kernel Version 11.4.0: Mon Apr 9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64

      Description

      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
      

        Attachments

          Activity

            People

            • Assignee:
              prokopec Aleksandar Prokopec
              Reporter:
              komamitsu Mitsunori Komatsu
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: