diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-05-08 23:17:20 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-05-08 23:17:20 +0200 |
commit | b5392a0f034afe23aff183d8673464c848f76241 (patch) | |
tree | 78344e4af58b661f2807856cfdcb2534ce92a2af | |
parent | 6dd0a364f775e507f0ffb983311c35f40d1e1939 (diff) | |
parent | c6b50282ab25c092af21b81080f863f8b44d08dc (diff) | |
download | scala-b5392a0f034afe23aff183d8673464c848f76241.tar.gz scala-b5392a0f034afe23aff183d8673464c848f76241.tar.bz2 scala-b5392a0f034afe23aff183d8673464c848f76241.zip |
Merge pull request #3704 from gourlaysama/wip/t8504
SI-8504 fix NPE in the Java wrapper for a Scala Map.
-rw-r--r-- | src/library/scala/collection/convert/Wrappers.scala | 2 | ||||
-rw-r--r-- | test/junit/scala/collection/convert/MapWrapperTest.scala | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/library/scala/collection/convert/Wrappers.scala b/src/library/scala/collection/convert/Wrappers.scala index 14ae57c43a..7d1d6b3781 100644 --- a/src/library/scala/collection/convert/Wrappers.scala +++ b/src/library/scala/collection/convert/Wrappers.scala @@ -194,7 +194,7 @@ private[collection] trait Wrappers { def getKey = k def getValue = v def setValue(v1 : B) = self.put(k, v1) - override def hashCode = byteswap32(k.hashCode) + (byteswap32(v.hashCode) << 16) + override def hashCode = byteswap32(k.##) + (byteswap32(v.##) << 16) override def equals(other: Any) = other match { case e: ju.Map.Entry[_, _] => k == e.getKey && v == e.getValue case _ => false diff --git a/test/junit/scala/collection/convert/MapWrapperTest.scala b/test/junit/scala/collection/convert/MapWrapperTest.scala index 060b6b5937..22eaf858ea 100644 --- a/test/junit/scala/collection/convert/MapWrapperTest.scala +++ b/test/junit/scala/collection/convert/MapWrapperTest.scala @@ -46,4 +46,14 @@ class MapWrapperTest { assertFalse(javaMap.containsKey(null)) // negative test, null key assertEquals(4, scalaMap.containsCounter) } + + // test for SI-8504 + @Test + def testHashCode() { + import scala.collection.JavaConverters._ + val javaMap = Map(1 -> null).asJava + + // Before the fix for SI-8504, this throws a NPE + javaMap.hashCode + } } |