{"record":{"id":"d27bac654dbac32d","repo":"apache/cassandra","slug":"function-argument-is-not-a-udt-but-a-datatype-ge","errorCode":null,"errorMessage":"Function argument is not a UDT but a ${dataType.getName()}","messagePattern":"Function argument is not a UDT but a (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/UDFContextImpl.java","lineNumber":120,"sourceCode":"        return newTupleValue(getArgumentTypeByIndex(argNum).toDataType());\n    }\n\n    public TupleValue newReturnTupleValue()\n    {\n        return newTupleValue(returnType.toDataType());\n    }\n\n    public TupleValue newTupleValue(String cqlDefinition)\n    {\n        AbstractType<?> abstractType = CQLTypeParser.parse(keyspace, cqlDefinition, metadata.get().types);\n        DataType dataType = JavaDriverUtils.driverType(abstractType);\n        return newTupleValue(dataType);\n    }\n\n    private static UDTValue newUDTValue(DataType dataType)\n    {\n        if (!(dataType instanceof UserType))\n            throw new IllegalStateException(\"Function argument is not a UDT but a \" + dataType.getName());\n        UserType userType = (UserType) dataType;\n        return userType.newValue();\n    }\n\n    private static TupleValue newTupleValue(DataType dataType)\n    {\n        if (!(dataType instanceof TupleType))\n            throw new IllegalStateException(\"Function argument is not a tuple type but a \" + dataType.getName());\n        TupleType tupleType = (TupleType) dataType;\n        return tupleType.newValue();\n    }\n\n    private UDFDataType getArgumentTypeByIndex(int index)\n    {\n        if (index < 0 || index >= argTypes.size())\n            throw new IllegalArgumentException(\"Function does not declare an argument with index \" + index);\n        return argTypes.get(index);\n    }","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/UDFContextImpl.java#L102-L138","documentation":"UDFContextImpl.newUDTValue expects the DataType of a function argument (or named/indexed argument) to be a UserType. When it is any other type, an IllegalStateException naming the actual type is thrown.","triggerScenarios":"Calling udfContext.newUDTValue() (or newArgUDTValue for an argument) whose declared CQL type is not a user-defined type — e.g. an int, text, or tuple argument.","commonSituations":"Copy-pasted UDF context code assuming all arguments are UDTs; schema changed so a column that was a UDT is now another type; wrong argument index/name passed to newArgUDTValue.","solutions":["Only call newUDTValue/newArgUDTValue for arguments declared as a UDT in CREATE FUNCTION","Check the argument's declared type and use the matching accessor (newTupleValue for tuples, newSet/List/MapValue for collections)","If the schema changed, update the UDF code to match the new argument types"],"exampleFix":"// before\nUDTValue v = context.newArgUDTValue(0); // arg 0 is an int\n// after\nint x = context.getInt(0); // use type-correct accessor","handlingStrategy":"type-guard","validationCode":"// Only request UDT values for UDT-typed arguments:\nif (!(argType instanceof UserType)) throw new IllegalArgumentException(\"arg is not a UDT: \" + argType);","typeGuard":"boolean isUdt(DataType t) { return t instanceof UserType; }","tryCatchPattern":"try { UDTValue v = ctx.newArgUDTValue(i); }\ncatch (IllegalStateException e) {\n  if (e.getMessage().contains(\"not a UDT\")) { /* fall back to a type-correct accessor */ }\n  else throw e;\n}","preventionTips":["Map each UDF argument's CQL type to the correct UDFContext accessor before coding the body","Re-check argument types after any schema change to UDT columns"],"tags":["udf","udt","type-mismatch","state"],"backgroundTag":"type-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}