{"record":{"id":"a6b52fd029ce23b6","repo":"apache/cassandra","slug":"initcond-must-not-be-empty-for-all-types-except-te","errorCode":null,"errorMessage":"INITCOND must not be empty for all types except TEXT, ASCII, BLOB","messagePattern":"INITCOND must not be empty for all types except TEXT, ASCII, BLOB","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateAggregateStatement.java","lineNumber":197,"sourceCode":"            if (null != initialValue)\n            {\n                try\n                {\n                    stateType.validate(initialValue);\n                }\n                catch (MarshalException e)\n                {\n                    throw ire(\"Invalid value for INITCOND of type %s\", stateType.asCQL3Type());\n                }\n            }\n\n            // Converts initcond to a CQL literal and parse it back to avoid another CASSANDRA-11064\n            String initialValueString = stateType.asCQL3Type().toCQLLiteral(initialValue);\n            if (!Objects.equal(initialValue, stateType.asCQL3Type().fromCQLLiteral(initialValueString)))\n                throw new AssertionError(String.format(\"CQL literal '%s' (from type %s) parsed with a different value\", initialValueString, stateType.asCQL3Type()));\n\n            if (Constants.NULL_LITERAL != rawInitialValue && isNullOrEmpty(stateType, initialValue))\n                throw ire(\"INITCOND must not be empty for all types except TEXT, ASCII, BLOB\");\n        }\n\n        if (!((UDFunction) stateFunction).isCalledOnNullInput() && null == initialValue)\n        {\n            throw ire(\"Cannot create aggregate '%s' without INITCOND because state function %s does not accept 'null' arguments\",\n                      aggregateName,\n                      stateFunctionName);\n        }\n\n        /*\n         * Create or replace\n         */\n\n        UDAggregate aggregate =\n            new UDAggregate(new FunctionName(keyspaceName, aggregateName),\n                            argumentTypes,\n                            returnType,\n                            (ScalarFunction) stateFunction,","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateAggregateStatement.java#L179-L215","documentation":"Thrown when INITCOND is explicitly provided (not NULL literal) but the value is empty/zero-length for a state type that does not permit empty values. Only TEXT, ASCII, and BLOB state types accept an empty (zero-length) INITCOND.","triggerScenarios":"CREATE AGGREGATE ... INITCOND '' (or another empty value) where STYPE is not text, ascii, or blob — e.g. INITCOND '' with STYPE int.","commonSituations":"Using '' as a generic 'default' value by habit; templated DDL generating INITCOND '' for all types; migrating aggregates between types without adjusting initcond.","solutions":["Use a type-appropriate non-empty initcond, e.g. INITCOND 0 for numeric STYPEs.","Use INITCOND only with text/ascii/blob if an empty value is genuinely desired.","Omit the INITCOND clause entirely (state function must accept null input in that case)."],"exampleFix":"// before\nCREATE AGGREGATE ks.c(int) SFUNC incr STYPE int INITCOND '';\n// after\nCREATE AGGREGATE ks.c(int) SFUNC incr STYPE int INITCOND 0;","handlingStrategy":"validation","validationCode":"boolean emptyAllowed = Set.of(\"text\",\"ascii\",\"blob\").contains(stateType.toLowerCase());\nif (!emptyAllowed && (initcond == null || initcond.isEmpty()))\n    throw new IllegalArgumentException(\"INITCOND must be non-empty for STYPE \" + stateType);","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); }\ncatch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"INITCOND must not be empty\")) { /* supply a type-appropriate initcond */ }\n    else throw e;\n}","preventionTips":["Never template INITCOND '' for numeric/collection STYPEs.","Only use empty-string initcond for text/ascii/blob."],"tags":["cql","initcond","empty-value"],"backgroundTag":"empty-required-field","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"}