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/08 11:50:12 UTC

[jira] Created: (HARMONY-6141) [classlib][luni] java.util.ArrayList.addAll(int index, Collection c) fails to add itself

[classlib][luni] java.util.ArrayList.addAll(int index, Collection<? extends E> c) fails to add itself
-----------------------------------------------------------------------------------------------------

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


Given a test case [1], both of these two scenarios are used to test java.util.ArrayList.addAll(int index, Collection<? extends E> c) method.

For scenario1, initialize two array list "arrayListA" and "arrayListB", add 1 to them respectively; then invoke arrayListA.addAll(arrayListB); finally "arrayListA" should be like [1, 1]
For scenario2, initialize an array list "arrayList", add one element to it; then try to add itself in the position of 1; finally "arrayList" should look like [1, 1] as well.

Conduct this test scenarios on RI and HY, RI passes all while HY fails on the 2nd scenario.

[1] Test Case:
public void test_ArrayList_addAll_scenario1() {
    ArrayList arrayListA = new ArrayList();
    arrayListA.add(1);
    ArrayList arrayListB = new ArrayList();
    arrayListB.add(1);
    arrayListA.addAll(1, arrayListB);
    int size = arrayListA.size();
    assertEquals(2, size);
    for (int index = 0; index < size; index++) {
        assertEquals(1, arrayListA.get(index));
    }
}

public void test_ArrayList_addAll_scenario2() {
    ArrayList arrayList = new ArrayList();
    arrayList.add(1);
    arrayList.addAll(1, arrayList);
    int size = arrayList.size();
    assertEquals(2, size);
    for (int index = 0; index < size; index++) {
        assertEquals(1, arrayList.get(index));
    }
}

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


[jira] Resolved: (HARMONY-6141) [classlib][luni] java.util.ArrayList.addAll(int index, Collection c) fails to add itself

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

Tim Ellison resolved HARMONY-6141.
----------------------------------

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

I tried to rework it a few times, but got myself totally confused because some of the local variables have already been modified before the collection is converted to an array, so the instance is all messed up.

I think it would be simpler and just as efficient to clone the collection if it is being added to itself.  What do you think?

Please take a look a the patch applied to the LUNI module at repo revision r772173.


> [classlib][luni] java.util.ArrayList.addAll(int index, Collection<? extends E> c) fails to add itself
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6141
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6141
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M8
>            Reporter: Kevin Zhou
>             Fix For: 5.0M10
>
>         Attachments: HARMONY-6141.diff
>
>
> Given a test case [1], both of these two scenarios are used to test java.util.ArrayList.addAll(int index, Collection<? extends E> c) method.
> For scenario1, initialize two array list "arrayListA" and "arrayListB", add 1 to them respectively; then invoke arrayListA.addAll(arrayListB); finally "arrayListA" should be like [1, 1]
> For scenario2, initialize an array list "arrayList", add one element to it; then try to add itself in the position of 1; finally "arrayList" should look like [1, 1] as well.
> Conduct this test scenarios on RI and HY, RI passes all while HY fails on the 2nd scenario.
> [1] Test Case:
> public void test_ArrayList_addAll_scenario1() {
>     ArrayList arrayListA = new ArrayList();
>     arrayListA.add(1);
>     ArrayList arrayListB = new ArrayList();
>     arrayListB.add(1);
>     arrayListA.addAll(1, arrayListB);
>     int size = arrayListA.size();
>     assertEquals(2, size);
>     for (int index = 0; index < size; index++) {
>         assertEquals(1, arrayListA.get(index));
>     }
> }
> public void test_ArrayList_addAll_scenario2() {
>     ArrayList arrayList = new ArrayList();
>     arrayList.add(1);
>     arrayList.addAll(1, arrayList);
>     int size = arrayList.size();
>     assertEquals(2, size);
>     for (int index = 0; index < size; index++) {
>         assertEquals(1, arrayList.get(index));
>     }
> }

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


[jira] Commented: (HARMONY-6141) [classlib][luni] java.util.ArrayList.addAll(int index, Collection c) fails to add itself

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6141?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12699632#action_12699632 ] 

Tim Ellison commented on HARMONY-6141:
--------------------------------------

I think we can do this more efficiently ... will think about it

> [classlib][luni] java.util.ArrayList.addAll(int index, Collection<? extends E> c) fails to add itself
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6141
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6141
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M8
>            Reporter: Kevin Zhou
>             Fix For: 5.0M9
>
>         Attachments: HARMONY-6141.diff
>
>
> Given a test case [1], both of these two scenarios are used to test java.util.ArrayList.addAll(int index, Collection<? extends E> c) method.
> For scenario1, initialize two array list "arrayListA" and "arrayListB", add 1 to them respectively; then invoke arrayListA.addAll(arrayListB); finally "arrayListA" should be like [1, 1]
> For scenario2, initialize an array list "arrayList", add one element to it; then try to add itself in the position of 1; finally "arrayList" should look like [1, 1] as well.
> Conduct this test scenarios on RI and HY, RI passes all while HY fails on the 2nd scenario.
> [1] Test Case:
> public void test_ArrayList_addAll_scenario1() {
>     ArrayList arrayListA = new ArrayList();
>     arrayListA.add(1);
>     ArrayList arrayListB = new ArrayList();
>     arrayListB.add(1);
>     arrayListA.addAll(1, arrayListB);
>     int size = arrayListA.size();
>     assertEquals(2, size);
>     for (int index = 0; index < size; index++) {
>         assertEquals(1, arrayListA.get(index));
>     }
> }
> public void test_ArrayList_addAll_scenario2() {
>     ArrayList arrayList = new ArrayList();
>     arrayList.add(1);
>     arrayList.addAll(1, arrayList);
>     int size = arrayList.size();
>     assertEquals(2, size);
>     for (int index = 0; index < size; index++) {
>         assertEquals(1, arrayList.get(index));
>     }
> }

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


[jira] Updated: (HARMONY-6141) [classlib][luni] java.util.ArrayList.addAll(int index, Collection c) fails to add itself

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

Kevin Zhou updated HARMONY-6141:
--------------------------------

    Attachment: HARMONY-6141.diff

Would you please help to try it?

> [classlib][luni] java.util.ArrayList.addAll(int index, Collection<? extends E> c) fails to add itself
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6141
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6141
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M8
>            Reporter: Kevin Zhou
>             Fix For: 5.0M9
>
>         Attachments: HARMONY-6141.diff
>
>
> Given a test case [1], both of these two scenarios are used to test java.util.ArrayList.addAll(int index, Collection<? extends E> c) method.
> For scenario1, initialize two array list "arrayListA" and "arrayListB", add 1 to them respectively; then invoke arrayListA.addAll(arrayListB); finally "arrayListA" should be like [1, 1]
> For scenario2, initialize an array list "arrayList", add one element to it; then try to add itself in the position of 1; finally "arrayList" should look like [1, 1] as well.
> Conduct this test scenarios on RI and HY, RI passes all while HY fails on the 2nd scenario.
> [1] Test Case:
> public void test_ArrayList_addAll_scenario1() {
>     ArrayList arrayListA = new ArrayList();
>     arrayListA.add(1);
>     ArrayList arrayListB = new ArrayList();
>     arrayListB.add(1);
>     arrayListA.addAll(1, arrayListB);
>     int size = arrayListA.size();
>     assertEquals(2, size);
>     for (int index = 0; index < size; index++) {
>         assertEquals(1, arrayListA.get(index));
>     }
> }
> public void test_ArrayList_addAll_scenario2() {
>     ArrayList arrayList = new ArrayList();
>     arrayList.add(1);
>     arrayList.addAll(1, arrayList);
>     int size = arrayList.size();
>     assertEquals(2, size);
>     for (int index = 0; index < size; index++) {
>         assertEquals(1, arrayList.get(index));
>     }
> }

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


[jira] Closed: (HARMONY-6141) [classlib][luni] java.util.ArrayList.addAll(int index, Collection c) fails to add itself

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

Kevin Zhou closed HARMONY-6141.
-------------------------------


Thanks, Tim. I'm OK with your new patch. It makes the code simpler and efficient.

> [classlib][luni] java.util.ArrayList.addAll(int index, Collection<? extends E> c) fails to add itself
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6141
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6141
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M8
>            Reporter: Kevin Zhou
>             Fix For: 5.0M10
>
>         Attachments: HARMONY-6141.diff
>
>
> Given a test case [1], both of these two scenarios are used to test java.util.ArrayList.addAll(int index, Collection<? extends E> c) method.
> For scenario1, initialize two array list "arrayListA" and "arrayListB", add 1 to them respectively; then invoke arrayListA.addAll(arrayListB); finally "arrayListA" should be like [1, 1]
> For scenario2, initialize an array list "arrayList", add one element to it; then try to add itself in the position of 1; finally "arrayList" should look like [1, 1] as well.
> Conduct this test scenarios on RI and HY, RI passes all while HY fails on the 2nd scenario.
> [1] Test Case:
> public void test_ArrayList_addAll_scenario1() {
>     ArrayList arrayListA = new ArrayList();
>     arrayListA.add(1);
>     ArrayList arrayListB = new ArrayList();
>     arrayListB.add(1);
>     arrayListA.addAll(1, arrayListB);
>     int size = arrayListA.size();
>     assertEquals(2, size);
>     for (int index = 0; index < size; index++) {
>         assertEquals(1, arrayListA.get(index));
>     }
> }
> public void test_ArrayList_addAll_scenario2() {
>     ArrayList arrayList = new ArrayList();
>     arrayList.add(1);
>     arrayList.addAll(1, arrayList);
>     int size = arrayList.size();
>     assertEquals(2, size);
>     for (int index = 0; index < size; index++) {
>         assertEquals(1, arrayList.get(index));
>     }
> }

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