Repeated calls to Map#apply results in crash
See original GitHub issueHere is a minification. In def wtf()
I create an immutable map and then call .apply
4 times. The first 3 times work but the 4th results in a NoSuchElementException
exception.
import utest._
final case class X(a: X.Y, b: X.Y)
object X {
final case class Y(value: Int)
def fromInts(i: Int, j: Int): X =
X(Y(i), Y(j))
new scala.collection.mutable.HashMap[Int, Int]()
}
object Bug extends TestSuite {
def v(i: Int, j: Int) = X.fromInts(i, j)
val v10 = v(1, 0)
val v11 = v(1, 1)
val v12 = v(1, 2)
val v20 = v(2, 0)
val v21 = v(2, 1)
def wtf() = {
val a = List(v10, v11, v12, v20, v21).iterator.zipWithIndex.toMap
println(a(v10)) // Prints 0
println(a(v10)) // Prints 0
println(a(v10)) // Prints 0
println(a(v10)) // Throws java.util.NoSuchElementException: key not found: X(Y(1),Y(0))
}
override def tests = Tests {
"wtf" - wtf()
}
}
There are some bizarre things to notice about this minification:
removing thenew scala.collection.mutable.HashMap[Int, Int]()
line avoids the bugsimilarly, prefixing it withlazy val x =
avoids the bug- changing
def v(i: Int, j: Int) = X.fromInts(i, j)
to useX(X.Y(i), X.Y(j))
directly, avoids the bug - moving the
val v10
lines fromobject Bug
to insidewtf()
avoids the bug - removing the
X.b
field so that there’s only one field avoids the bug - unboxing the
X
fields to just be twoInt
s avoids the bug - creating a map of less than 5 items avoids the bug (makes sense cos they use different implementations)
moving everything out ofBug
into a different objectZ
, then changing the test line to"wtf" - Z.wtf()
avoids the bug
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (14 by maintainers)
Top Results From Across the Web
Master Pandas Map, Apply, and Applymap in 5 minutes
It may cause your computer to crash due to the extreme amount of memory requirement. The map function does not also cause a...
Read more >crash with many threads in java · Issue #4231 - GitHub
In our testing we would crash within a half hour on a 8-core machine running 20 threads with JRE 1.6. ... Reference counting...
Read more >crash(8) - Linux manual page - man7.org
Crash is a tool for interactively analyzing the state of the Linux system while it is running, or after a kernel crash has...
Read more >White Paper: Crash Utility
The crash analysis utility is loosely based on the SVR4 UNIX crash command, but has been significantly enhanced by completely merging it with...
Read more >Generating and handling application traceback on crash
This feature describes a few tools to help you generate a traceback, a chain of all function calls that the application was executing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Btw, if anyone else comes across this issue in future, the higher-level problem I had was that I was using
airbnb-js-shims
in my tests because some other dependency was usingMap
andSet
.A workaround for this is to switch from
airbnb-js-shims
tocore-js
. In my case I simply imported'core-js/features/map'
and'core-js/features/set'
and problem avoided.Thanks for the repro. Due to the giant SIP meeting, I won’t have time to look at it until next week.
Just from the set of things needed to reproduce, my hunch is that the shim for
imul
implemented in es6-shims is either fundamentally buggy, or somehow triggers a bug in PhantomJS. The shim that is built in Scala.js seems to be correct, since not having es6-shims causes the bug not to surface, following your comment.