Also dissallow null elements on set

This commit is contained in:
Norman Maurer 2013-07-12 08:25:19 +02:00
parent 98c6a5810a
commit 3a4c7c9c93

View File

@ -25,7 +25,7 @@ import java.util.List;
import java.util.RandomAccess;
/**
* A simple list that holds the output of a codec.
* A simple list which is reyclable. This implementation does not allow {@code null} elements to be added.
*/
public final class RecyclableArrayList extends ArrayList<Object> {
@ -79,7 +79,7 @@ public final class RecyclableArrayList extends ArrayList<Object> {
return super.addAll(index, c);
}
private void checkNullElements(Collection<?> c) {
private static void checkNullElements(Collection<?> c) {
if (c instanceof RandomAccess && c instanceof List) {
// produce less garbage
List<?> list = (List<?>) c;
@ -114,6 +114,14 @@ public final class RecyclableArrayList extends ArrayList<Object> {
super.add(index, element);
}
@Override
public Object set(int index, Object element) {
if (element == null) {
throw new NullPointerException("element");
}
return super.set(index, element);
}
/**
* Clear and recycle this instance.
*/