RFR: 8079136: Accessing a nested sublist leads to StackOverflowError
Ivan Gerasimov
ivan.gerasimov at oracle.com
Wed May 6 14:08:08 UTC 2015
Hello everyone!
Here's the second iteration of the fix.
BUGURL: https://bugs.openjdk.java.net/browse/JDK-8079136
WEBREV: http://cr.openjdk.java.net/~igerasim/8079136/1/webrev/
I changed all the sub-list classes to be non internal, but standalone.
I think the logic become more obvious now.
ArrayList.SubList was renamed to ArraySubList, so it didn't conflict
with SubList from AbstractList.java.
The test now uses testng.
I didn't come up with a good comment for the SubLists constructors yet.
I'll update it a bit later.
Comments, suggestions are very welcome.
Sincerely yours,
Ivan
On 05.05.2015 10:17, Ivan Gerasimov wrote:
> Hello!
>
> When creating a sublist with List.subList(), it keeps a reference to
> its parent.
> Then, when accessing (get(), set(), add(), remove(), etc.) the
> sublist, it recursively calls the corresponding methods of its parent.
> This recursion, when deep enough, can cause StackOverflowError.
>
> The only reason to do things recursively here, is the need to update
> modCount and size of all the parents.
> So, the proposal is to update these fields in a loop.
>
> A few cleanups were done along the way.
>
> Would you please help review the fix?
>
> BUGURL: https://bugs.openjdk.java.net/browse/JDK-8079136
> WEBREV: http://cr.openjdk.java.net/~igerasim/8079136/0/webrev/
>
> Sincerely yours,
> Ivan
>
>
More information about the core-libs-dev
mailing list