{"record":{"id":"b17585297bcbe62a","repo":"apache/cassandra","slug":"a-user-type-cannot-contain-counters-b17585","errorCode":null,"errorMessage":"A user type cannot contain counters","messagePattern":"A user type cannot contain counters","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTypeStatement.java","lineNumber":112,"sourceCode":"\n        UserType existingType = keyspace.types.getNullable(bytes(typeName));\n        if (null != existingType)\n        {\n            if (ifNotExists)\n                return schema;\n\n            throw ire(\"A user type with name '%s' already exists\", typeName);\n        }\n\n        Set<FieldIdentifier> usedNames = new HashSet<>();\n        for (FieldIdentifier name : fieldNames)\n            if (!usedNames.add(name))\n                throw ire(\"Duplicate field name '%s' in type '%s'\", name, typeName);\n\n        for (CQL3Type.Raw type : rawFieldTypes)\n        {\n            if (type.isCounter())\n                throw ire(\"A user type cannot contain counters\");\n\n            if (type.isUDT() && !type.isFrozen())\n                throw ire(\"A user type cannot contain non-frozen UDTs\");\n        }\n\n        List<AbstractType<?>> fieldTypes =\n            rawFieldTypes.stream()\n                         .map(t -> t.prepare(keyspaceName, keyspace.types).getType())\n                         .collect(toList());\n\n        UserType udt = new UserType(keyspaceName, bytes(typeName), fieldNames, fieldTypes, true);\n        return schema.withAddedOrUpdated(keyspace.withSwapped(keyspace.types.with(udt)));\n    }\n\n    SchemaChange schemaChangeEvent(KeyspacesDiff diff)\n    {\n        return new SchemaChange(Change.CREATED, Target.TYPE, keyspaceName, typeName);\n    }","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTypeStatement.java#L94-L130","documentation":"Validation guard in CreateTypeStatement.apply() fired while creating a user-defined type: one of the declared field types is a counter type. Cassandra UDTs are stored as static schema metadata with no write path for counter increments, so a counter field inside a UDT is illegal; the create is rejected with InvalidRequestException before the schema change is applied.","triggerScenarios":"Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTypeStatement.java:112 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the counter-typed field from the CREATE TYPE declaration and create the type again without it; if counters are required, keep them in a regular counter table instead of a UDT; nest or reference counter data by primary key rather than embedding it in the UDT."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}