I wrote a Monte Carlo player for the Nine Men Morris board game. Everything is basically unchanged. The program includes many futures (hundreds) and many modifications of immutable Maps. Sometimes I get a failure with the following exception:
java.lang.NullPointerException
at scala.collection.mutable.HashTable$class.elemHashCode(HashTable.scala:154)
at scala.collection.immutable.HashMap.elemHashCode(HashMap.scala:41)
at scala.collection.mutable.HashTable$class.findEntry(HashTable.scala:66)
at scala.collection.immutable.HashMap.findEntry(HashMap.scala:41)
at scala.collection.immutable.HashMap.undo$1(HashMap.scala:132)
at scala.collection.immutable.HashMap.undo$1(HashMap.scala:130)
at scala.collection.immutable.HashMap.makeCopy(HashMap.scala:154)
at scala.collection.immutable.HashMap.makeCopyIfUpdated(HashMap.scala:161)
at scala.collection.immutable.HashMap.update(HashMap.scala:66)
at scala.collection.immutable.Map$class.$plus(Map.scala:66)
at scala.collection.immutable.HashMap.$plus(HashMap.scala:41)
at morris.players.MapBasedMorrisBoard.applyMove(MapBasedMorrisBoard.scala:30)
at morris.players.MonteCarloPlayer$$anonfun$main$1$$anonfun$apply$1.apply(MonteCarloPlayer.scala:77)
at morris.players.MonteCarloPlayer$$anonfun$main$1$$anonfun$apply$1.apply(MonteCarloPlayer.scala:77)
at scala.actors.Futures$$anonfun$2$$anonfun$apply$1.apply(Future.scala:45)
at scala.actors.Futures$$anonfun$2$$anonfun$apply$1.apply(Future.scala:44)
at scala.actors.Reaction.run(Reaction.scala:78)
at scala.actors.FJTask$Wrap.run(Unknown Source)
at scala.actors.FJTaskRunner.scanWhileIdling(Unknown Source)
at scala.actors.FJTaskRunner.run(Unknown Source)
I use immutable Maps, so I wonder if this is caused by an error in my own code or if it could be an error in the scala library. When you look at the trace, you can see that there are calls to the mutable HashTable down the stack. Perhaps this is causing concurrency issues?
The code inside my program where an exception occurs simply adds another collection to the immutable map:
myMap ++ (someInteger -> aValue)
Edit: The same program without concurrency works flawlessly.