Closed
Description
Using Scala 2.11.6 with Java 1.8.0_111 on Ubuntu 16.04.2 LTS.
I have the following code
import scala.reflect.runtime.universe.{Type, typeOf}
object bug {
trait PA[+AttrType]
def main(args: Array[String]): Unit = {
val lock = new Object()
0 until 100 foreach { t =>
(0 until Runtime.getRuntime.availableProcessors() * 4).par.foreach { id =>
val someStringProperty: Type = typeOf[PA[String]]
val someProperty: Type = typeOf[PA[_]]
/*lock.synchronized*/ {
if (!(someStringProperty <:< someProperty))
println("Is not subtype in iteration " + t)
}
}
}
}
}
I get this output when I run the above in a loop:
$ while true; do scala bug.scala; done
Is not subtype in iteration 2
Is not subtype in iteration 1
Is not subtype in iteration 0
Is not subtype in iteration 11
Is not subtype in iteration 69
Is not subtype in iteration 6
Is not subtype in iteration 90
Is not subtype in iteration 16
Is not subtype in iteration 0
Is not subtype in iteration 2
Is not subtype in iteration 0
It's expected that someStringProperty
be a subtype of someProperty
, and someStringProperty <:< someProperty
returns true most of the time. But when used in multiple threads (on a cold JVM) it appears to sometimes returns false.
The problem seems to go away if I add a synchronized keyword around the subtype check.