during a debugging I encountered the following strange behaviour.
Here's the code:
ArrayList<String> selectedCardsIDs = new ArrayList<String>();
for (int i=0; i<this.selectedCards.size(); i++)
selectedCardsIDs.add(this.selectedCards.get(i).getId());
In my debug I have initially this.selectedCards.size() = 3, after the
first cycle it becomes strangely this.selectedCards.size() = 2!
I have to specify that this.selectedCards.get(i).getId() it's just a
getter...
Anyone can find an answer?
Thank you!
--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---
Is there multithreaded (or unmultithreaded) code elsewhere modifying the
size of the list? Is your debugging tests somehow modifying the size of
the list?
The code works, it was just modified by another code via a pointer of an
element of the list.
does selectedCards.get(index) remove the item from the list, thus
reducing the list's size by one?
--
Fred K
Yup no problem.
>
>Anyone can find an answer?
What you could do is write a wrapper around ArrayList that dumps the
size of the array and a stack trace any time it could be potentially
changed.
You could also simply trace the code in a debugger, and watch where
the size changes unexpectedly.
In IntelliJ there is a feature to find all references to a given
variable. Check there are no strays pointing to your ArrayList.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Microsoft has a new version out, Windows XP, which according to everybody is the "most reliable Windows ever." To me, this is like saying that asparagus is "the most articulate vegetable ever."
~ Dave Barry