Bug 463539 - SlotIterator.remove does not comply with java.util.Iterator.remove
Summary: SlotIterator.remove does not comply with java.util.Iterator.remove
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: BIRT (show other bugs)
Version: 4.4.2   Edit
Hardware: PC Windows 7
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: Birt-ReportDesigner CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-31 01:15 EDT by Barney Barumba CLA
Modified: 2015-03-31 01:50 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Barney Barumba CLA 2015-03-31 01:15:41 EDT
When removing items using SlotIterator#remove it does not comply with the java.util.Iterator requirements.

Using a test report design with two or more data sources...

This code fails to remove the first element from the collection:

    Iterator iter = design.getDataSources().iterator();
    while (iter.hasNext()) {
      Object dataSource = iter.next();
      // do something with dataSource...
      iter.remove();
    }

This code does work, but should throw a IllegalStateException:

    Iterator iter= design.getDataSources().iterator();
    while (iter.hasNext()) {
      iter.remove();
    }

As per the java.util.Iterator#remove javadoc: "Throws: IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method."

There's an easy workaround, just not using the iterator:

    SlotHandle dataSources = design.getDataSources();
    while (dataSources.getCount() > 0) {
      Object dataSource = dataSources.get(0);
      // do something with dataSource...
      dataSources.dropAndClear(0);
    }