You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling hashCode on a java map wrapper fails, because hashCode in Wrappers.scala (line 190) calls v.hashCode without checking for null. This seems unexpected since calling hashCode on a scala map works fine even if it contains a null value (and I believe the same goes for java).
It also breaks some iteration constructs; for example, calling .zipWithIndex on a wrapped map containing a wrapped map that has a null value throws a NullPointerException
Here's a stack trace/how to reproduce:
Simple case:
❯ scala 1 ↵
Welcome to Scala version 2.10.2 (JavaHotSpot(TM) 64-BitServerVM, Java1.7.0_40).
Type in expressions to have them evaluated.
Type:help for more information.
scala>importscala.collection.JavaConversions._importscala.collection.JavaConversions._
scala>valscalaMap=Map(1->null)
scalaMap: scala.collection.immutable.Map[Int,Null] =Map(1->null)
scala>valjavaMap= mapAsJavaMap(scalaMap)
javaMap: java.util.Map[Int,Null] = {1=null}
scala> scalaMap.hashCode
res0:Int=1600778741
scala> javaMap.hashCode
java.lang.NullPointerException
at scala.collection.convert.Wrappers$MapWrapper$$anon$1$$anon$5$$anon$6.hashCode(Wrappers.scala:190)
at java.util.AbstractMap.hashCode(AbstractMap.java:494)
at .<init>(<console>:13)
at .<clinit>(<console>)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:745)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:790)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:702)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:566)
at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:573)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:576)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:867)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:83)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Case where zipWithIndex breaks:
scala>valjavaMap2= mapAsJavaMap(Map(1->2, 3-> mapAsJavaMap(Map(4->null))))
javaMap2: java.util.Map[Int,Any] = {1=2, 3={4=null}}
scala> javaMap2.zipWithIndex
java.lang.NullPointerException
at scala.collection.convert.Wrappers$MapWrapper$$anon$1$$anon$5$$anon$6.hashCode(Wrappers.scala:190)
at java.util.AbstractMap.hashCode(AbstractMap.java:494)
at scala.runtime.ScalaRunTime$.hash(ScalaRunTime.scala:214)
at scala.util.hashing.MurmurHash3.productHash(MurmurHash3.scala:63)
at scala.util.hashing.MurmurHash3$.productHash(MurmurHash3.scala:210)
at scala.runtime.ScalaRunTime$._hashCode(ScalaRunTime.scala:176)
at scala.Tuple2.hashCode(Tuple2.scala:19)
at scala.runtime.ScalaRunTime$.hash(ScalaRunTime.scala:214)
at scala.collection.mutable.HashTable$HashUtils$class.elemHashCode(HashTable.scala:398)
at scala.collection.mutable.HashMap.elemHashCode(HashMap.scala:39)
at scala.collection.mutable.HashTable$class.findOrAddEntry(HashTable.scala:161)
at scala.collection.mutable.HashMap.findOrAddEntry(HashMap.scala:39)
at scala.collection.mutable.HashMap.$plus$eq(HashMap.scala:89)
at scala.collection.mutable.HashMap.$plus$eq(HashMap.scala:39)
at scala.collection.IterableLike$$anonfun$zipWithIndex$1.apply(IterableLike.scala:268)
at scala.collection.IterableLike$$anonfun$zipWithIndex$1.apply(IterableLike.scala:267)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.IterableLike$class.zipWithIndex(IterableLike.scala:267)
at scala.collection.AbstractIterable.zipWithIndex(Iterable.scala:54)
at .<init>(<console>:12)
at .<clinit>(<console>)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:745)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:790)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:702)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:566)
at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:573)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:576)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:867)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:83)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
The text was updated successfully, but these errors were encountered:
Calling hashCode on a java map wrapper fails, because hashCode in Wrappers.scala (line 190) calls v.hashCode without checking for null. This seems unexpected since calling hashCode on a scala map works fine even if it contains a null value (and I believe the same goes for java).
It also breaks some iteration constructs; for example, calling .zipWithIndex on a wrapped map containing a wrapped map that has a null value throws a NullPointerException
Here's a stack trace/how to reproduce:
Simple case:
Case where zipWithIndex breaks:
The text was updated successfully, but these errors were encountered: