{"record":{"id":"324c365e673464a0","repo":"apache/cassandra","slug":"field-s-doesn-t-exist-in-type-s-s","errorCode":null,"errorMessage":"Field '%s' doesn't exist in type '%s.%s'","messagePattern":"Field '(.+?)' doesn't exist in type '(.+?)\\.(.+?)'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/UserType.java","lineNumber":535,"sourceCode":"                            securityLabel,\n                            fieldComments,\n                            fieldSecurityLabels);\n    }\n\n    public UserType withComment(String comment)\n    {\n        return new UserType(keyspace, name, fieldNames, fieldTypes(), isMultiCell(), comment, securityLabel, fieldComments, fieldSecurityLabels);\n    }\n\n    public UserType withSecurityLabel(String securityLabel)\n    {\n        return new UserType(keyspace, name, fieldNames, fieldTypes(), isMultiCell(), comment, securityLabel, fieldComments, fieldSecurityLabels);\n    }\n\n    public UserType withFieldComment(FieldIdentifier fieldName, String fieldComment)\n    {\n        if (fieldPosition(fieldName) == -1)\n            throw new IllegalArgumentException(String.format(\"Field '%s' doesn't exist in type '%s.%s'\", fieldName, keyspace, getNameAsString()));\n\n        Map<FieldIdentifier, String> newFieldComments = new HashMap<>(fieldComments);\n        if (fieldComment == null || fieldComment.isEmpty())\n            newFieldComments.remove(fieldName);\n        else\n            newFieldComments.put(fieldName, fieldComment);\n\n        return new UserType(keyspace, name, fieldNames, fieldTypes(), isMultiCell(), comment, securityLabel, newFieldComments, fieldSecurityLabels);\n    }\n\n    public UserType withFieldSecurityLabel(FieldIdentifier fieldName, String fieldSecurityLabel)\n    {\n        if (fieldPosition(fieldName) == -1)\n            throw new IllegalArgumentException(String.format(\"Field '%s' doesn't exist in type '%s.%s'\", fieldName, keyspace, getNameAsString()));\n\n        Map<FieldIdentifier, String> newFieldSecurityLabels = new HashMap<>(fieldSecurityLabels);\n        if (fieldSecurityLabel == null || fieldSecurityLabel.isEmpty())\n            newFieldSecurityLabels.remove(fieldName);","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/UserType.java#L517-L553","documentation":"UserType.withFieldComment returns a copy of the UDT type with a comment attached to a specific field. If the given FieldIdentifier does not match any declared field (fieldPosition returns -1), an IllegalArgumentException with this message is thrown — the schema is not modified.","triggerScenarios":"Calling withFieldComment with a FieldIdentifier created from a misspelled or renamed field name, or on a different UDT instance than the one owning the field.","commonSituations":"Schema migration tooling applying comments after a field rename; case mismatch between the identifier and the declared field; hardcoded field names in ALTER TYPE drivers.","solutions":["Verify the field exists with fieldPosition(fieldName) != -1 before calling","Fetch the exact FieldIdentifier from fieldNames() of the same UserType instance","Use ALTER TYPE ... ALTER field to check names via cqlsh / DESCRIBE TYPE"],"exampleFix":"// before\nnewType = udt.withFieldComment(FieldIdentifier.forUnquoted(\"usernme\"), \"the name\"); // IllegalArgumentException\n// after\nFieldIdentifier f = FieldIdentifier.forUnquoted(\"username\");\nif (udt.fieldPosition(f) != -1)\n    newType = udt.withFieldComment(f, \"the name\");","handlingStrategy":"validation","validationCode":"if (udt.fieldPosition(fieldName) == -1) throw new IllegalArgumentException(\"Unknown field \" + fieldName + \" in \" + udt.getNameAsString());","typeGuard":"boolean fieldExists(UserType t, FieldIdentifier f) { return t.fieldPosition(f) != -1; }","tryCatchPattern":"try { return udt.withFieldComment(field, comment); } catch (IllegalArgumentException e) { throw new SchemaException(\"field not in UDT: \" + field); }","preventionTips":["Derive FieldIdentifier values from udt.fieldNames()","Re-fetch schema metadata after any ALTER TYPE","Unit-test schema migration helpers against current definitions"],"tags":["cassandra","udt","schema","illegal-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}