New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Appending a ListBuffer to itself causes endless loop #3088
Comments
Imported From: https://issues.scala-lang.org/browse/SI-3088?orig=1 |
@paulp said: |
@paulp said: def hasNext: Boolean = !start.isEmpty && (cursor ne last0) && (elementsRemaining > 0) |
anyone know where the fix for this is? I can't find it |
update: it actually re-emerged at some point during or before 2.13. it just so happens that the test only checks when the |
If LB doesn't support self-append, then it should throw IllegalArgumentException if passed an instance of itself. But maybe a better fix would be to look at the number of elements in the LB at the start of the append, and just append that many.
The easy "fix" is to add something to the Javadoc or assume that users will be able to diagnose the OutOfMemoryError that results, but the self-append may not be so obvious as the one in this example and could lead to a OutOfMemoryError in a production system, potentially taking the whole system down instead of just one thread. Imagine if this happened on a web server. If ListBuffer threw IllegalArgumentException, then just the one request would fail. If it instead allocates all the available memory, then it will grind the CPU for a while, slowing down everything else, and potentially cause other requests that need memory to fail too.
I think that the same issue probably affects the prepend operations.
The text was updated successfully, but these errors were encountered: