Skip to content

Commit

Permalink
Adjusted a test in InspectorShorthandsSpec as weird scala.collection.…
Browse files Browse the repository at this point in the history
…parallel.mutable.ParFlatHashTable behavior when handling null value in scala 2.11-M5.
  • Loading branch information
cheeseng committed Jan 20, 2014
1 parent fa42db3 commit f28781d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/test/scala/org/scalatest/InspectorShorthandsSpec.scala
Expand Up @@ -648,19 +648,25 @@ class InspectorShorthandsSpec extends Spec with Matchers with TableDrivenPropert
}

def `should throw TestFailedException with correct stack depth and message when 'not be null' failed` {
forAll(nullableExamples) { colFun =>
forAll(nullableExamples) { colFun =>
val col =
try {
Some(colFun(Set("1", null, "3")))
val theCol = colFun(Set("1", null, "3"))
// Let's double check if the collection handle null correctly, in 2.11-M8, this cause
// java.lang.ClassCastException: scala.collection.mutable.FlatHashTable$NullSentinel$ cannot be cast to java.lang.String

This comment has been minimized.

Copy link
@adriaanm

adriaanm Jan 21, 2014

This should've been fixed by scala/scala#1839 -- is it still a problem?

This comment has been minimized.

Copy link
@cheeseng

cheeseng Jan 22, 2014

Author Owner

It seems to be still a problem:

console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.11.0-M8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.

scala> val set = collection.mutable.Set("1", null, "3").par
set: scala.collection.parallel.mutable.ParSet[String] = ParHashSet(null, 3, 1)

scala> set.exists(_ == null)
java.lang.ClassCastException: scala.collection.mutable.FlatHashTable$NullSentinel$ cannot be cast to java.lang.String
at $anonfun$1.apply(:9)
at scala.collection.Iterator$class.exists(Iterator.scala:769)
at scala.collection.parallel.mutable.ParFlatHashTable$ParFlatHashTableIterator.exists(ParFlatHashTable.scala:27)
at scala.collection.parallel.ParIterableLike$Exists.leaf(ParIterableLike.scala:1089)
at scala.collection.parallel.Task$$anonfun$tryLeaf$1.apply$mcV$sp(Tasks.scala:49)
at scala.collection.parallel.Task$$anonfun$tryLeaf$1.apply(Tasks.scala:48)
at scala.collection.parallel.Task$$anonfun$tryLeaf$1.apply(Tasks.scala:48)
at scala.collection.parallel.Task$class.tryLeaf(Tasks.scala:51)
at scala.collection.parallel.ParIterableLike$Exists.tryLeaf(ParIterableLike.scala:1086)
at scala.collection.parallel.AdaptiveWorkStealingTasks$WrappedTask$class.internal(Tasks.scala:159)
at scala.collection.parallel.AdaptiveWorkStealingForkJoinTasks$WrappedTask.internal(Tasks.scala:443)
at scala.collection.parallel.AdaptiveWorkStealingTasks$WrappedTask$class.compute(Tasks.scala:149)
at scala.collection.parallel.AdaptiveWorkStealingForkJoinTasks$WrappedTask.compute(Tasks.scala:443)
at scala.concurrent.forkjoin.RecursiveAction.exec(RecursiveAction.java:160)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

scala>

This comment has been minimized.

Copy link
@adriaanm

adriaanm Jan 22, 2014

Thanks for confirming -- could've tried that myself, sorry :)
/cc @Ichoran, could you take a look?

This comment has been minimized.

Copy link
@Ichoran

Ichoran Feb 2, 2014

Is there an issue corresponding to this? A bug report makes it more likely that it'll get fixed than if there's only a line note in some other repository.

This comment has been minimized.

Copy link
@cheeseng

cheeseng via email Feb 4, 2014

Author Owner
// for scala.collection.parallel.mutable.ParFlatHashTable (index 14 in nullableExamples)
theCol.exists(_ == null)
Some(theCol)
}
catch {
case iae: IllegalArgumentException =>
//case iae: IllegalArgumentException =>
case t: Throwable =>
// Some collection cannot contains null value, e.g. mutable.Set
None
}

col match {
case Some(col) =>
case Some(col) if col.exists(_ == null) =>
val e2 = intercept[exceptions.TestFailedException] {
all(col) should not be (null)
}
Expand Down

0 comments on commit f28781d

Please sign in to comment.