apache/iceberg · error · IllegalArgumentException
Arguments cannot both be null
Error message
Arguments cannot both be null
What it means
ArrayUtil.add(array, element) determines the component type of the new array from either the existing array or the element. If both are null, no type can be inferred, so it throws IllegalArgumentException with 'Arguments cannot both be null'.
Solutions
- Ensure at least one of the arguments is non-null before calling add
- Initialize the target array with a concrete type instead of null
- Provide an explicit element (or an empty array of the correct component type) for the first add
Example fix
// before T[] result = ArrayUtil.add(array, maybeNullElement); // after Preconditions.checkNotNull(maybeNullElement, "element cannot be null"); T[] result = ArrayUtil.add(array, maybeNullElement);
Defensive patterns
Strategy: type-guard
Validate before calling
if (array == null && element == null) throw new IllegalArgumentException("array and element cannot both be null"); Type guard
static <T> boolean addable(T[] array, T element) { return array != null || element != null; } Try / catch
try { result = ArrayUtil.add(array, element); } catch (IllegalArgumentException e) { /* initialize array with proper type */ } Prevention
- Initialize accumulation arrays with a concrete component type
- Null-check the first element before the first add call
- Prefer collections (List) over array-growing helpers during accumulation
When it happens
Trigger: Calling ArrayUtil.add(null, null) — e.g., accumulating into an array variable that was never initialized and whose first element is also null.
Common situations: Generic accumulation code where the array is lazily initialized to null and the element comes from a lookup that returned null; refactored code paths that pass through untyped nulls.
Related errors
- Buffer size of is larger than requested size of
- Cannot find a snapshot after
- Cannot load metadata: metadata file location is null
- Insufficient bytes in buffer
- Null key metadata buffer
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/dc326f6f5351f622.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/apache/iceberg/util/ArrayUtil.java:293
* This code is borrowed from `org.apache.commons:commons-lang3`.
*
* @param <T> the component type of the array
* @param array the array to "add" the element to, may be {@code null}
* @param element the object to add, may be {@code null}
* @return A new array containing the existing elements plus the new element The returned array
* type will be that of the input array (unless null), in which case it will have the same
* type as the element. If both are null, an IllegalArgumentException is thrown
* @since 2.1
* @throws IllegalArgumentException if both arguments are null
*/
public static <T> T[] add(final T[] array, final T element) {
Class<?> type;
if (array != null) {
type = array.getClass().getComponentType();
} else if (element != null) {
type = element.getClass();
} else {
throw new IllegalArgumentException("Arguments cannot both be null");
}
@SuppressWarnings("unchecked") // type must be T
final T[] newArray = (T[]) copyArrayGrow1(array, type);
newArray[newArray.length - 1] = element;
return newArray;
}
/**
* Returns a copy of the given array of size 1 greater than the argument. The last value of the
* array is left to the default value.
*
* <p>This code is borrowed from `org.apache.commons:commons-lang3`.
*
* @param array The array to copy, must not be {@code null}.
* @param newArrayComponentType If {@code array} is {@code null}, create a size 1 array of this
* type.
* @return A new copy of the array of size 1 greater than the input.
*/View on GitHub (pinned to 86d9c8fc54)