• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Problem with Iterator

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi



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.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 was born with webbed fish toes. This tiny ad is my only friend:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic