/** * Validates a new content object and returns the validated object. * This implementation checks for null, if {@link #canContainNull necessary} and returns the argument object. * Clients may throw additional types of runtime exceptions * in order to handle constraint violations. * @param index the position of the new content. * @param object the new content. * @return the validated content. * @exception IllegalArgumentException if a constraint prevents the object from being added. */ protected E validate(int index, E object) { if (!canContainNull() && object == null) { throw new IllegalArgumentException("The 'no null' constraint is violated"); } return object; }