Dissallow adding null elements into RecyclableArrayList

This commit is contained in:
Norman Maurer 2013-07-12 08:01:31 +02:00
parent be963d4caf
commit c38db2afe3

View File

@ -20,6 +20,7 @@ import io.netty.util.Recycler;
import io.netty.util.Recycler.Handle;
import java.util.ArrayList;
import java.util.Collection;
/**
* A simple list that holds the output of a codec.
@ -64,6 +65,42 @@ public final class RecyclableArrayList extends ArrayList<Object> {
this.handle = handle;
}
@Override
public boolean addAll(Collection<?> c) {
for (Object element: c) {
if (element == null) {
throw new IllegalArgumentException("c contains null values");
}
}
return super.addAll(c);
}
@Override
public boolean addAll(int index, Collection<?> c) {
for (Object element: c) {
if (element == null) {
throw new IllegalArgumentException("c contains null values");
}
}
return super.addAll(index, c);
}
@Override
public boolean add(Object element) {
if (element == null) {
throw new NullPointerException("element");
}
return super.add(element);
}
@Override
public void add(int index, Object element) {
if (element == null) {
throw new NullPointerException("element");
}
super.add(index, element);
}
/**
* Clear and recycle this instance.
*/