apache/cassandra · error · IllegalArgumentException

Field '%s' doesn't exist in type '%s.%s'

Error message

Field '%s' doesn't exist in type '%s.%s'

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/UserType.java:535

                            securityLabel,
                            fieldComments,
                            fieldSecurityLabels);
    }

    public UserType withComment(String comment)
    {
        return new UserType(keyspace, name, fieldNames, fieldTypes(), isMultiCell(), comment, securityLabel, fieldComments, fieldSecurityLabels);
    }

    public UserType withSecurityLabel(String securityLabel)
    {
        return new UserType(keyspace, name, fieldNames, fieldTypes(), isMultiCell(), comment, securityLabel, fieldComments, fieldSecurityLabels);
    }

    public UserType withFieldComment(FieldIdentifier fieldName, String fieldComment)
    {
        if (fieldPosition(fieldName) == -1)
            throw new IllegalArgumentException(String.format("Field '%s' doesn't exist in type '%s.%s'", fieldName, keyspace, getNameAsString()));

        Map<FieldIdentifier, String> newFieldComments = new HashMap<>(fieldComments);
        if (fieldComment == null || fieldComment.isEmpty())
            newFieldComments.remove(fieldName);
        else
            newFieldComments.put(fieldName, fieldComment);

        return new UserType(keyspace, name, fieldNames, fieldTypes(), isMultiCell(), comment, securityLabel, newFieldComments, fieldSecurityLabels);
    }

    public UserType withFieldSecurityLabel(FieldIdentifier fieldName, String fieldSecurityLabel)
    {
        if (fieldPosition(fieldName) == -1)
            throw new IllegalArgumentException(String.format("Field '%s' doesn't exist in type '%s.%s'", fieldName, keyspace, getNameAsString()));

        Map<FieldIdentifier, String> newFieldSecurityLabels = new HashMap<>(fieldSecurityLabels);
        if (fieldSecurityLabel == null || fieldSecurityLabel.isEmpty())
            newFieldSecurityLabels.remove(fieldName);

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Verify the field exists with fieldPosition(fieldName) != -1 before calling
  2. Fetch the exact FieldIdentifier from fieldNames() of the same UserType instance
  3. Use ALTER TYPE ... ALTER field to check names via cqlsh / DESCRIBE TYPE

Example fix

// before
newType = udt.withFieldComment(FieldIdentifier.forUnquoted("usernme"), "the name"); // IllegalArgumentException
// after
FieldIdentifier f = FieldIdentifier.forUnquoted("username");
if (udt.fieldPosition(f) != -1)
    newType = udt.withFieldComment(f, "the name");
Defensive patterns

Strategy: validation

Validate before calling

if (udt.fieldPosition(fieldName) == -1) throw new IllegalArgumentException("Unknown field " + fieldName + " in " + udt.getNameAsString());

Type guard

boolean fieldExists(UserType t, FieldIdentifier f) { return t.fieldPosition(f) != -1; }

Try / catch

try { return udt.withFieldComment(field, comment); } catch (IllegalArgumentException e) { throw new SchemaException("field not in UDT: " + field); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/324c365e673464a0. Report an issue: GitHub.