[concurrency-interest] Iterator does not work after removal of lastelement

David Holmes dholmes at dltech.com.au
Thu May 12 02:41:55 EDT 2005


This is a known bug. See the first listed item at:

http://gee.cs.oswego.edu/dl/concurrency-interest/post-tiger.html

and
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6215625

Unfortunately this is not yet fixed in 1.5 and we don't know yet whether it
will be.

David Holmes
  -----Original Message-----
  From: concurrency-interest-bounces at cs.oswego.edu
[mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of
Shyamal.Mehta at trilogy.com
  Sent: Thursday, 12 May 2005 3:56 PM
  To: concurrency-interest at altair.cs.oswego.edu
  Subject: [concurrency-interest] Iterator does not work after removal of
lastelement



  While using the LinkedBlockingQueue, I found the following behavior:

  Once the remove method is called on the queue when only one element is
present in it, the iterator returned by any subsequent calls to iterator()
method (even after we have filled more elements in the queue), returns an
iterator that behaves that the queue is empty.

  I have attached the test program I wrote to verify this. Is it a bug or am
I missing something?

  The same behavior is shown when using JDK 1.5 too.

  Thanks,
  Shyamal




  import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue;
  import java.util.Iterator;

  public class TestConcurrent
  {
          public static void main(String[] args)
          {
          try
          {
              LinkedBlockingQueue q = new LinkedBlockingQueue();
              Integer data;
              Iterator iter;
              for (int i = 1; i <= 100 ; i++ )
              {

                  data = new Integer(i);
                  q.add(data);

                  System.out.print("Inserted " + i + " th element. Queue
size is " + q.size() + ". ");
                  iter = q.iterator();
                  int count = 0;
                  while ( iter.hasNext() )
                  {
                      iter.next();
                      count++;
                  }
                  System.out.println("Iterator found " + count + " elements.
");

                  /*
                  Removing the element by either of the two ways (by the
queue's
                  remove method or the iterator's remove method) results in
an
                  iterator being returned (on the next call of iterator()
method)
                  that always behaves as if the queue is empty.
                  If we use the queue's take method to remove elements, that
works.
                  */
                  q.remove(data);

                  /*iter = q.iterator();
                  count = 0;
                  while ( iter.hasNext() )
                  {
                      iter.next();
                      iter.remove();
                      count++;
                  }
                  System.out.println(" Removed "+count+" elements.");*/

                  //q.take();

              }
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
          }
  }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20050512/26cfa9c0/attachment.htm


More information about the Concurrency-interest mailing list