Bug 43536

Summary: CopyOnWriteArrayList bug in delete() when empty
Product: classpath Reporter: Eric Marsden <ecmarsden>
Component: classpathAssignee: Not yet assigned to anyone <unassigned>
Severity: normal CC: bug-classpath, ecmarsden, gnu_andrew
Priority: P3    
Version: 0.98   
Target Milestone: 0.99   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Eric Marsden 2010-03-26 12:08:31 UTC
When deleting an element from an CopyOnWriteArrayList, a spurious exception is

% 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) {

    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

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

Comment 3 Andrew John Hughes 2012-02-15 23:39:59 UTC
Target to 0.99.