JDK-6533203 : (coll) AbstractList.ListItr.add might corrupt iterator state if enclosing add throws
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-03-11
  • Updated: 2012-10-08
  • Resolved: 2011-05-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b15Fixed
Related Reports
Relates :  
Description
While following up on

6529795: (coll) Iterator.remove() fails if next() threw NoSuchElementException

it was noticed that AbstractList.ListItr.add(E) has a similar very small blemish.
if enclosing add fails, then the iterator might be modified, possibly into an impossible
state.

Comments
EVALUATION Submitter is correct.
11-03-2007

SUGGESTED FIX --- /u/martin/ws/dolphin/src/share/classes/java/util/AbstractList.java 2007-01-06 19:36:59.140396000 -0800 +++ /u/martin/ws/Iter7/src/share/classes/java/util/AbstractList.java 2007-03-10 16:47:37.688167000 -0800 @@ -420,8 +422,10 @@ checkForComodification(); try { - AbstractList.this.add(cursor++, e); + int i = cursor; + AbstractList.this.add(i, e); lastRet = -1; + cursor = i + 1; expectedModCount = modCount; } catch (IndexOutOfBoundsException ex) { throw new ConcurrentModificationException();
11-03-2007