In the above code snippet, a set of ids are present in the padviceSet in as strings. Now Using Iterator i'm trying to create a list of Advices (an object). The problem I am facing is that when I am debuging my code in Eclipse the insert() method is not called and no desired output is resulted. But on direct running the code thru web browser the "pas" is set properly, insert is called and desired output generated.
I doubt there is some problem with the iteration logic. Please help me. Also, I get NoSuchElementException on iter.next() call.
It sounds to me as if the program is multithreaded, and some other thread is removing items from padviceIdSet as you're trying to iterate over it (although I'd expect a ConcurrentModificationException in that case -- but perhaps the failsafe mechanism is... failing.) I don't see any kind of synchronization here.
In any case, this would explain how drastic timing changes could cause a difference.
Yes, another thread removing items does seem the most likely cause of the problem here. You might also take a look at this "StringSet", which is not a standard library class. It could be that the iterator() method here is returning a buggy implementation. Might be worth a look, especially if you're not using multiple threads in your program.
This could also be why you're not seeing a ConcurrentModificationException - the StringSet code may not be designed to throw one. Note that this is not a bug per se, as throwing ConcurrentModificationException is not part of the responsibilities of any Collection interface. It's just that many specific implementations do throw CME (or try to, in most cases). But some don't, and this is perfectly acceptable.
"I'm not back." - Bill Harding, Twister
I was born with webbed fish toes. This tiny ad is my only friend: