You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Kevin Zhou <zh...@gmail.com> on 2009/04/10 10:21:56 UTC

Re: [jira] Created: (HARMONY-6145) [classlib][luni] java.lang.LinkedList.addAll(Collection collection) runs into endless loop

Hi,
I have investigated this defect.
This problem happens on two methods [1][2] of java.lang.LinkedList class.
Initialize a LinkedList and add element at the last position. Then adding
this linkedList to itself will trigger a endless loop.

The root cause is that the implementation of the above addAll methods adds
elements directly from linkList itself which will also change the added
linkList.
It should transfer the added collection into an array, then add elements
from that array rather than directly from the linkList itself.

[1] public boolean addAll(Collection<? extends E> c)
[2] public boolean addAll(int index, Collection<? extends E> c)

Re: [jira] Created: (HARMONY-6145) [classlib][luni] java.lang.LinkedList.addAll(Collection collection) runs into endless loop

Posted by Kevin Zhou <zh...@gmail.com>.
:)

On Fri, Apr 10, 2009 at 5:53 PM, Kevin Zhou <zh...@gmail.com> wrote:

> When add a collection to itself, this endless loop results from increasing
> of collection due to adding elements.
> Other collections that implements set or map interface will only have sole
> element. Thus adding self will not change the size.
>
> Therefore, only collections implements List or Queue may possibly results
> in such failure.
>
> Till now, I don't find any other class that fails on this.
>
>
> On Fri, Apr 10, 2009 at 5:30 PM, Regis <xu...@gmail.com> wrote:
>
>> Kevin Zhou wrote:
>>
>>> Hi,
>>> I have investigated this defect.
>>> This problem happens on two methods [1][2] of java.lang.LinkedList class.
>>> Initialize a LinkedList and add element at the last position. Then adding
>>> this linkedList to itself will trigger a endless loop.
>>>
>>> The root cause is that the implementation of the above addAll methods
>>> adds
>>> elements directly from linkList itself which will also change the added
>>> linkList.
>>> It should transfer the added collection into an array, then add elements
>>> from that array rather than directly from the linkList itself.
>>>
>>> [1] public boolean addAll(Collection<? extends E> c)
>>> [2] public boolean addAll(int index, Collection<? extends E> c)
>>>
>>>
>> Does the endless loop happen in other collection's addAll() methods?
>>
>> --
>> Best Regards,
>> Regis.
>>
>
>

Re: [jira] Created: (HARMONY-6145) [classlib][luni] java.lang.LinkedList.addAll(Collection collection) runs into endless loop

Posted by Kevin Zhou <zh...@gmail.com>.
When add a collection to itself, this endless loop results from increasing
of collection due to adding elements.
Other collections that implements set or map interface will only have sole
element. Thus adding self will not change the size.

Therefore, only collections implements List or Queue may possibly results in
such failure.

Till now, I don't find any other class that fails on this.

On Fri, Apr 10, 2009 at 5:30 PM, Regis <xu...@gmail.com> wrote:

> Kevin Zhou wrote:
>
>> Hi,
>> I have investigated this defect.
>> This problem happens on two methods [1][2] of java.lang.LinkedList class.
>> Initialize a LinkedList and add element at the last position. Then adding
>> this linkedList to itself will trigger a endless loop.
>>
>> The root cause is that the implementation of the above addAll methods adds
>> elements directly from linkList itself which will also change the added
>> linkList.
>> It should transfer the added collection into an array, then add elements
>> from that array rather than directly from the linkList itself.
>>
>> [1] public boolean addAll(Collection<? extends E> c)
>> [2] public boolean addAll(int index, Collection<? extends E> c)
>>
>>
> Does the endless loop happen in other collection's addAll() methods?
>
> --
> Best Regards,
> Regis.
>

Re: [jira] Created: (HARMONY-6145) [classlib][luni] java.lang.LinkedList.addAll(Collection collection) runs into endless loop

Posted by Regis <xu...@gmail.com>.
Kevin Zhou wrote:
> Hi,
> I have investigated this defect.
> This problem happens on two methods [1][2] of java.lang.LinkedList class.
> Initialize a LinkedList and add element at the last position. Then adding
> this linkedList to itself will trigger a endless loop.
> 
> The root cause is that the implementation of the above addAll methods adds
> elements directly from linkList itself which will also change the added
> linkList.
> It should transfer the added collection into an array, then add elements
> from that array rather than directly from the linkList itself.
> 
> [1] public boolean addAll(Collection<? extends E> c)
> [2] public boolean addAll(int index, Collection<? extends E> c)
> 

Does the endless loop happen in other collection's addAll() methods?

-- 
Best Regards,
Regis.