-
Notifications
You must be signed in to change notification settings - Fork 21
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
Various mutable collections do not handle calling addAll, subtractAll, insertAll with themselves as an arg well #12121
Comments
(Iterator-specificity was addressed, so I removed that part.) Though it's not obvious at first thought, So we probably ought to check for self in every mutable collection in cases where we can't just change the algorithm to do it right. Maybe I can add a test to collections-laws once the collections are fixed. Hangs are annoying to handle in test frameworks, though. I guess I put it into a thread and kill it if it takes too long. Anything done with indexes, for instance, can just cache the length of the target. (This makes it more vulnerable to error with concurrent modification, but you're already playing with fire there, so I think it's worth the tradeoff.) |
you're right. I updated the description |
Checking for self is not a solution, because you can always hide that by passing a proxy that forwards all methods to self: val b = ...
val c = new BufferProxy(b)
b ++= c The latter should work if |
@sjrd - Yes, I thought of that, but I don't see a bincompat way to get it to work. Safe-by-design approaches like caching the length are best. Otherwise you'd need a new method, e.g. At some point it's up to the user not to muck stuff up. I guess the question is whether we just define |
I agree; however, I don't see a good way to make it work, unfortunately. Personally, I think we should still at least try to get |
similar methods with potentially the same problem: |
I'm sorry. titles are hard. if github could cut out the middle ones that didn't last more than like 2 minutes, that would be nice Edit: and I still left out |
@sjrd one possibility for adding elements to get even proxies to work would be to convert to the collection passed in to the internal representation before modifying it's less obvious what should be done for |
also |
reproduction steps
using Scala 2.13
problem
Various mutable collections use iterators over themselves or
foreach
to append to themselves. With iterators, this is an unsafe use of iterators and tends to produce iterators that never exhaust (because they include the new elements appended). Withforeach
, the call tends to never end because the collection keeps getting larger.I have not determined the full scope of the problem; only that at least
ListBuffer
is included, and that the default implementation inGrowable
is also included.The text was updated successfully, but these errors were encountered: