Bug 43536 - CopyOnWriteArrayList bug in delete() when empty
Summary: CopyOnWriteArrayList bug in delete() when empty
Status: RESOLVED FIXED
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: 0.98
: P3 normal
Target Milestone: 0.99
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-26 12:08 UTC by Eric Marsden
Modified: 2012-02-15 23:39 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Marsden 2010-03-26 12:08:31 UTC
When deleting an element from an CopyOnWriteArrayList, a spurious exception is
raised. 

% jamvm Foo
Exception in thread "main" java.lang.NegativeArraySizeException
   at java.util.concurrent.CopyOnWriteArrayList.remove(CopyOnWriteArrayList.java:455)
   at Foo.removeListener(Foo.java:18)
   at Foo.main(Foo.java:23)

The same code functions correctly with openjdk6. 

Below is code to reproduce the issue.

----------------------------------------------------------------------
import java.util.concurrent.CopyOnWriteArrayList;

public class Foo {
    private CopyOnWriteArrayList<Boolean> listeners;

    public Foo() {
        listeners = new CopyOnWriteArrayList<Boolean>();
    }

    public void removeListener(Boolean listener) {
        listeners.remove(listener);
    }

    public static void main(String[] arguments) {
        Foo myFoo = new Foo();
        myFoo.removeListener(new Boolean(true));
    }   
}
Comment 1 Eric Marsden 2010-03-26 12:10:24 UTC
Suggestion: line 454 of CopyOnWriteArrayList.java in remove() method, exit 
immediately if the backing array is empty. 
Comment 2 Andrew John Hughes 2010-05-11 21:19:46 UTC
This issue has now been fixed:

2010-04-27  Andrew Haley  <aph@redhat.com>

        * java/util/concurrent/CopyOnWriteArrayList.java: Fix for empty
        list.

I've added a test for this bug to our test suite, Mauve:

http://sources.redhat.com/ml/mauve-patches/2010/msg00000.html
Comment 3 Andrew John Hughes 2012-02-15 23:39:59 UTC
Target to 0.99.