question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repeated calls to Map#apply results in crash

See original GitHub issue

Here 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 the new scala.collection.mutable.HashMap[Int, Int]() line avoids the bug
  • similarly, prefixing it with lazy val x = avoids the bug
  • changing def v(i: Int, j: Int) = X.fromInts(i, j) to use X(X.Y(i), X.Y(j)) directly, avoids the bug
  • moving the val v10 lines from object Bug to inside wtf() 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 two Ints avoids the bug
  • creating a map of less than 5 items avoids the bug (makes sense cos they use different implementations)
  • moving everything out of Bug into a different object Z, then changing the test line to "wtf" - Z.wtf() avoids the bug

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
japgollycommented, Mar 14, 2020

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 using Map and Set.

A workaround for this is to switch from airbnb-js-shims to core-js. In my case I simply imported 'core-js/features/map' and 'core-js/features/set' and problem avoided.

1reaction
sjrdcommented, Mar 11, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found