Weird problem/observation with Sequence remove() [message #872040] |
Tue, 15 May 2012 11:04 |
Maarten Bezemer Messages: 117 Registered: February 2012 |
Senior Member |
|
|
Hi,
I noticed something really strange and am unsure what to do with it.
A simple representation of the problematic code (including my bug):
var index = 0;
while(index < list.size()) {
var item = list.get(index);
if(not item.allowProcess()) {
index = index + 1;
continue;
}
list.remove(index);
index = 0;
-- Process item and generate code (but absolutely not using list anymore!)
}
Note: that list (Sequence) dot not contain numbers/integers but a certain selection of the objects (extending EObject) of the model. The list got filled with something like diagram.getObjects().select(d|d.shouldSelect()).
The observant reader should notice the bug by now: list.remove(index) should have been list.removeAt(index).
So far so good.
My actual problem is that the example code did work for weeks!
A Windows user finally got an OutOfMemory error as item was processed a infinite amount of times. As it should be due to the bug.
All Mac and Linux users (including myself) did not experience any problems. Processing with large or small lists does not seem to matter.
Personally, I got really surprised by this!
So, the reason of this post: is the a known problem/bug? Are there differences between Windows and other OSes at all? (with respect to Epsilon of course )
As I am kind of busy with deadlines, I did not yet have time to create a minimal example. If this is desired (because of the weirdness of this problem), please let me know and I'll try to make time for this.
[Updated on: Tue, 15 May 2012 11:07] Report message to a moderator
|
|
|
Re: Weird problem/observation with Sequence remove() [message #872057 is a reply to message #872040] |
Tue, 15 May 2012 11:49 |
|
Hi Maarten,
Actually, yes: that's a known bug that happens when storing integers in a collection. We've got a test for it, and oddly it passes in some operating systems (Windows) and fails in others (UNIX variants like MacOS X or Linux). It assumes that "remove(2)" is interpreted as "remove '2' from the collection", which is the other way around as in your sample code.
The problem here is that in some OS "remove(2)" is interpreted as "remove(int)" or "remove by index", and in other OS "remove(2)" is interpreted as "remove(Object)" = "remove the first occurrence of the element". We've pinned the bug to some odd difference in the way reflection and autoboxing work in the JVM across operating systems, but we haven't found yet a way to reliably work around it. removeAt is guaranteed to remove by index as you said, though.
Is this a showstopper for you, or would it be enough to document the issue for now?
Antonio
|
|
|
Re: Weird problem/observation with Sequence remove() [message #872078 is a reply to message #872057] |
Tue, 15 May 2012 12:19 |
Maarten Bezemer Messages: 117 Registered: February 2012 |
Senior Member |
|
|
Hello Antonio,
Thanks for your detailed explanation. I am not storing integers in the collection, but other from this the problem is exactly as your describe.
As I noted earlier, I switched to removeAt() to remove a certain index (as I should have used from the start). So for this particular situation it is solved for me.
Only problem is that I do not know for sure, whether I did make this mistake in other places as well, which are 'accepted' because I develop and test under Linux.
So it is not a showstopper, but until yesterday I thought my code was ok. Now I need to check for remove() occurrences and verify they are correct...
For the short term, a notice about this known issue, to warn (future) developers to be careful, in the documentation is good enough I suppose.
On the longer run, this definitely needs to be fixed of course.
Maarten
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03596 seconds