{"record":{"id":"213ea64e57808ba6","repo":"apache/cassandra","slug":"name-is-not-a-field-defined-in-this-definition","errorCode":null,"errorMessage":"<name> is not a field defined in this definition","messagePattern":"<name> is not a field defined in this definition","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/UserType.java","lineNumber":185,"sourceCode":"    {\n        return Iterators.forArray(byIdx);\n    }\n\n    /**\n     * Returns the type of a given field.\n     *\n     * @param name the name of the field. Note that {@code name} obey the usual CQL identifier rules:\n     *             it should be quoted if it denotes a case sensitive identifier (you can use {@link\n     *             Metadata#quote} for the quoting).\n     * @return the type of field {@code name} if this UDT has a field of this name, {@code null}\n     * otherwise.\n     * @throws IllegalArgumentException if {@code name} is not a field of this UDT definition.\n     */\n    DataType getFieldType(String name)\n    {\n        int[] idx = byName.get(Metadata.handleId(name));\n        if (idx == null)\n            throw new IllegalArgumentException(name + \" is not a field defined in this definition\");\n\n        return byIdx[idx[0]].getType();\n    }\n\n    @Override\n    public boolean isFrozen()\n    {\n        return frozen;\n    }\n\n    public UserType copy(boolean newFrozen)\n    {\n        if (newFrozen == frozen)\n        {\n            return this;\n        }\n        else\n        {","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/UserType.java#L167-L203","documentation":"UserType.getFieldType(name) looks up the field's index in the UDT definition's byName map and throws this IllegalArgumentException when the name is absent. Same family as UDTValue field lookup failures: the driver's in-memory UDT definition does not contain the requested field name.","triggerScenarios":"userType.getFieldType(\"emaill\") (typo), calling before the type definition includes a newly added field (schema refreshed later), passing identifier casing inconsistent with Metadata.handleId normalization.","commonSituations":"Code-generated accessors generated from an older schema version; rolling schema migrations where nodes/drivers see different definitions; quoted vs unquoted identifier casing differences.","solutions":["List available fields via the UserType definition (getFieldNames) and correct the name.","After server-side ALTER TYPE, call cluster.refreshSchemaMetadata() or reconnect to pick up the new field.","Normalize the name the same way Metadata.handleId does (case sensitivity rules) before lookup.","Regenerate code that hard-codes field names from the current schema."],"exampleFix":"// before\nDataType t = userType.getFieldType(\"Emaill\"); // typo\n// after\nDataType t = userType.getFieldType(\"email\"); // matches definition","handlingStrategy":"validation","validationCode":"if (userType.getFieldNames().stream().noneMatch(f -> f.asInternal().equalsIgnoreCase(name))) throw new IllegalArgumentException(\"field not in UDT: \" + name);","typeGuard":null,"tryCatchPattern":"try { return userType.getFieldType(name); } catch (IllegalArgumentException e) { cluster.refreshSchemaMetadata(); return userType.getFieldType(name); } // one retry after refresh","preventionTips":["Cache field-name lists from the definition, not from code","Refresh metadata after any DDL","Use Metadata.handleId-consistent casing for lookups"],"tags":["udt","schema","type-lookup"],"backgroundTag":"resource-not-found","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"}