apache/cassandra · error · IllegalArgumentException
Function does not declare an argument with index
Error message
Function does not declare an argument with index ${index} What it means
getArgumentTypeByIndex validates that the requested index exists in the function's declared argument list; if the index is negative or >= the number of arguments, an IllegalArgumentException is thrown. It backs newArgUDTValue and newArgTupleValue in UDFContextImpl.
Solutions
- Use an index within 0..(number of declared arguments - 1)
- Prefer the by-name variant (newArgUDTValue("arg_name")) to avoid index drift when signatures change
- Update the UDF code whenever the CREATE FUNCTION argument list changes
Example fix
// before (3-arg function) TupleValue tv = context.newArgTupleValue(3); // out of range // after TupleValue tv = context.newArgTupleValue(2); // last valid index
Defensive patterns
Strategy: validation
Validate before calling
// Validate index against the declared argument count:
if (index < 0 || index >= argTypes.size()) throw new IndexOutOfBoundsException("no arg at index " + index); Type guard
boolean hasArg(int i, int argCount) { return i >= 0 && i < argCount; } Try / catch
try { TupleValue tv = ctx.newArgTupleValue(i); }
catch (IllegalArgumentException e) {
if (e.getMessage().contains("does not declare an argument")) { /* clamp index or use by-name lookup */ }
else throw e;
} Prevention
- Prefer by-name accessors (newArgTupleValue("name")) over indices
- Re-verify hard-coded indices whenever the function signature changes
When it happens
Trigger: Calling udfContext.newArgTupleValue(i) or newArgUDTValue(i) with an index outside [0, argCount) — e.g. index 3 in a 3-argument function, or a negative index.
Common situations: Off-by-one errors after changing the function's argument list; hard-coded indices that no longer match CREATE FUNCTION; loops using argCount instead of argCount-1.
Related errors
- Function argument is not a tuple type but a
- Function argument is not a UDT but a
- 0x0000
- A range supplied to SSTableCursorReader ends before it…
- Access denied
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/19855db0c631170f.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/functions/UDFContextImpl.java:136
{
if (!(dataType instanceof UserType))
throw new IllegalStateException("Function argument is not a UDT but a " + dataType.getName());
UserType userType = (UserType) dataType;
return userType.newValue();
}
private static TupleValue newTupleValue(DataType dataType)
{
if (!(dataType instanceof TupleType))
throw new IllegalStateException("Function argument is not a tuple type but a " + dataType.getName());
TupleType tupleType = (TupleType) dataType;
return tupleType.newValue();
}
private UDFDataType getArgumentTypeByIndex(int index)
{
if (index < 0 || index >= argTypes.size())
throw new IllegalArgumentException("Function does not declare an argument with index " + index);
return argTypes.get(index);
}
private UDFDataType getArgumentTypeByName(String argName)
{
UDFDataType arg = byName.get(argName);
if (arg == null)
throw new IllegalArgumentException("Function does not declare an argument named '" + argName + '\'');
return arg;
}
}
View on GitHub (pinned to 88fd0f6a0e)