Question: We're getting this error

```
java.lang.NullPointerException
    at java.util.ArrayList.<init>(Unknown Source)
    at de.mystuff.ExtendedArrayList.<init>(ExtendedArrayList.java:38)

```

where ExtendedArrayList:38 is

```
new ArrayList(new ArrayCollection<E>(data));

```

In short: the ArrayList constructor sometimes seems to choke on our home grown Collection implementation ArrayCollection.

I was unable to reproduce it on my computer even with the exact same version that was distributed to our customers.

But i'm not 100% sure that they are using the JRE we included.
So, i googled for some ArrayList.java source code and found openJDK 6b17 which has this

```
public ArrayList(Collection<? extends E> c) {
    elementData = c.toArray();
    size = elementData.length;
    // c.toArray might (incorrectly) not return Object[] (see 6260652)
    if (elementData.getClass() != Object[].class)
        elementData = Arrays.copyOf(elementData, size, Object[].class);
}

```

That would make sense, because if there's no data our *ArrayCollection.toArray()* returns **null**. And this constructor looked safe (and worked without exception) for the 1.5.0\_09 Sun JDK/JRE implementation we are using.  

But openJDK only seems to release for the unix world. Is this code also part of a Windows JRE? And if so, which version?

NB: I know that we have to fix our classes, but i want to make sure i understand the cause of the NullPointerException.

Answer: 
Why do you think that it's legitimate to return null rather than returning a zero-length array?

The javadoc for `List` does not allow for this. So, the cause is that all the other JRE's make the same assumption. The Sun implementation's published sources on my Mac certainly make that assumption.
The List#toArray method should never return null. Your implementation of ArrayCollection may have overriden the toArray methods and may be returning null for empty collections instead of a new empty array.

And yes, it is possible that different JRE's behave differently. Some may tolerate null instead of an array while others don't.

I'd fire up my [Java decompiler](http://java.decompiler.free.fr/) and have a look at the actual implementation of this ArrayList constructor.