RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

Ivan Gerasimov ivan.gerasimov at oracle.com
Fri May 8 14:49:19 UTC 2015

Hi Doug!

On 07.05.2015 22:23, Doug Lea wrote:
> On 05/06/2015 07:23 PM, Martin Buchholz wrote:
>> Hi Ivan,
>> I'm afraid of these changes - they are hard to review.
> I believe that they also break the AbstractList.subList spec.
> http://docs.oracle.com/javase/8/docs/api/java/util/AbstractList.html#subList-int-int- 
The @implSpec section currently says:
      * The subclass stores, in private fields, the
      * offset of the subList within the backing list, the size of the 
      * (which can change over its lifetime), and the expected
      * {@code modCount} value of the backing list.

With the proposed change, the sublist will still store the same information:
offset withing the backing list  :=  this.offset - (parent == null ? 0 : 
size is stored as before,
expected modCount of the backing list is stored as before, but now it is 
compared with root.modCount.

I think that the proposed fix formally conforms to the spec.

However, I'm not really sure why all this details have to be listed in 
the javadoc.
Can we just remove them? (with the CCC, of course)

> The reason that flattened forms were not used is that each
> layer does not in general know the class of its parent.

I'm inclined to create another regression test which will systematically 
check the behavior of sublists.
Even though the changes in the fix are quite straight-forward, it's 
still better to make sure nothing is broken.

> However, flattened forms are used in java.util.ArrayList.SubList.
> It would be possible (and easy) to create a specialization for the
> java.util.Arrays.ArrayList class (i.e., the kind returned by
> Arrays.asList(a).subList), which would also fix the SOE problem
> in this particular case.

Yes.  The same can be done for Collections.SingletonList too.
If AbstractList had a base class, that implements sublists without 
tracking down any structural modifications, it could be used as the base 
class for Arrays.ArrayList and Collections.SingletonList.

I think it should better be done as a separate enhancement, though.

Sincerely yours,

More information about the core-libs-dev mailing list