You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Kevin Zhou (JIRA)" <ji...@apache.org> on 2009/04/10 10:10:13 UTC

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

[classlib][luni] java.lang.LinkedList.addAll(Collection<? extends E> collection) runs into endless loop
-------------------------------------------------------------------------------------------------------

                 Key: HARMONY-6145
                 URL: https://issues.apache.org/jira/browse/HARMONY-6145
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
    Affects Versions: 5.0M8
            Reporter: Kevin Zhou
            Priority: Critical
             Fix For: 5.0M9


Given a test case [1], RI successfully passes it while HY runs into endless loop.

[1] Test Case:
public void test_addAll_Self_Ljava_util_Collection() {
    LinkedList linkedList = new LinkedList();
    linkedList.addLast(1);
    assertEquals(1, linkedList.size());
    assertTrue(linkedList.addAll(linkedList));
    assertEquals(2, linkedList.size());
}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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.

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

Posted by Kevin Zhou <zh...@gmail.com>.
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)

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

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Ellison resolved HARMONY-6145.
----------------------------------

    Resolution: Fixed

Thank you Kevin.

I have modified your patch so that the common case, of adding a collection that is not the same as the receiver, does not copy into a new Array.  I think it is better to save time and space for this most common case.

Please see modified patch applied to LUNI module at repo revision r765552 and check it solves the problem for you.


> [classlib][luni] java.lang.LinkedList.addAll(Collection<? extends E> collection) runs into endless loop
> -------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6145
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6145
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M8
>            Reporter: Kevin Zhou
>            Assignee: Tim Ellison
>            Priority: Critical
>             Fix For: 5.0M9
>
>         Attachments: HARMONY-6145.diff
>
>
> Given a test case [1], RI successfully passes it while HY runs into endless loop.
> [1] Test Case:
> public void test_addAll_Self_Ljava_util_Collection() {
>     LinkedList linkedList = new LinkedList();
>     linkedList.addLast(1);
>     assertEquals(1, linkedList.size());
>     assertTrue(linkedList.addAll(linkedList));
>     assertEquals(2, linkedList.size());
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Kevin Zhou (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kevin Zhou updated HARMONY-6145:
--------------------------------

    Attachment: HARMONY-6145.diff

Would you please help to try it?

> [classlib][luni] java.lang.LinkedList.addAll(Collection<? extends E> collection) runs into endless loop
> -------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6145
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6145
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M8
>            Reporter: Kevin Zhou
>            Priority: Critical
>             Fix For: 5.0M9
>
>         Attachments: HARMONY-6145.diff
>
>
> Given a test case [1], RI successfully passes it while HY runs into endless loop.
> [1] Test Case:
> public void test_addAll_Self_Ljava_util_Collection() {
>     LinkedList linkedList = new LinkedList();
>     linkedList.addLast(1);
>     assertEquals(1, linkedList.size());
>     assertTrue(linkedList.addAll(linkedList));
>     assertEquals(2, linkedList.size());
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Kevin Zhou (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kevin Zhou closed HARMONY-6145.
-------------------------------


The new patch is good.
Thanks, Tim. :)

> [classlib][luni] java.lang.LinkedList.addAll(Collection<? extends E> collection) runs into endless loop
> -------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6145
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6145
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M8
>            Reporter: Kevin Zhou
>            Assignee: Tim Ellison
>            Priority: Critical
>             Fix For: 5.0M9
>
>         Attachments: HARMONY-6145.diff
>
>
> Given a test case [1], RI successfully passes it while HY runs into endless loop.
> [1] Test Case:
> public void test_addAll_Self_Ljava_util_Collection() {
>     LinkedList linkedList = new LinkedList();
>     linkedList.addLast(1);
>     assertEquals(1, linkedList.size());
>     assertTrue(linkedList.addAll(linkedList));
>     assertEquals(2, linkedList.size());
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Ellison reassigned HARMONY-6145:
------------------------------------

    Assignee: Tim Ellison

> [classlib][luni] java.lang.LinkedList.addAll(Collection<? extends E> collection) runs into endless loop
> -------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6145
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6145
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M8
>            Reporter: Kevin Zhou
>            Assignee: Tim Ellison
>            Priority: Critical
>             Fix For: 5.0M9
>
>         Attachments: HARMONY-6145.diff
>
>
> Given a test case [1], RI successfully passes it while HY runs into endless loop.
> [1] Test Case:
> public void test_addAll_Self_Ljava_util_Collection() {
>     LinkedList linkedList = new LinkedList();
>     linkedList.addLast(1);
>     assertEquals(1, linkedList.size());
>     assertTrue(linkedList.addAll(linkedList));
>     assertEquals(2, linkedList.size());
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Ellison updated HARMONY-6145:
---------------------------------

    Fix Version/s:     (was: 5.0M9)
                   5.0M10

> [classlib][luni] java.lang.LinkedList.addAll(Collection<? extends E> collection) runs into endless loop
> -------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6145
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6145
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M8
>            Reporter: Kevin Zhou
>            Assignee: Tim Ellison
>            Priority: Critical
>             Fix For: 5.0M10
>
>         Attachments: HARMONY-6145.diff
>
>
> Given a test case [1], RI successfully passes it while HY runs into endless loop.
> [1] Test Case:
> public void test_addAll_Self_Ljava_util_Collection() {
>     LinkedList linkedList = new LinkedList();
>     linkedList.addLast(1);
>     assertEquals(1, linkedList.size());
>     assertTrue(linkedList.addAll(linkedList));
>     assertEquals(2, linkedList.size());
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.