{"record":{"id":"eeb4d9616fa6020d","repo":"apache/cassandra","slug":"invalid-number-of-components-expecting-d-but-got","errorCode":null,"errorMessage":"Invalid number of components, expecting %d but got %d","messagePattern":"Invalid number of components, expecting (.+?) but got (.+?)","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/ClusteringComparator.java","lineNumber":125,"sourceCode":"        return clusteringTypes.get(i);\n    }\n\n    /**\n     * Creates a row clustering based on the clustering values.\n     * <p>\n     * Every argument can either be a {@code ByteBuffer}, in which case it is used as-is, or a object\n     * corresponding to the type of the corresponding clustering column, in which case it will be\n     * converted to a byte buffer using the column type.\n     *\n     * @param values the values to use for the created clustering. There should be exactly {@code size()}\n     * values which must be either byte buffers or of the type the column expect.\n     *\n     * @return the newly created clustering.\n     */\n    public Clustering<?> make(Object... values)\n    {\n        if (values.length != size())\n            throw new IllegalArgumentException(String.format(\"Invalid number of components, expecting %d but got %d\", size(), values.length));\n\n        CBuilder builder = CBuilder.create(this);\n        for (Object val : values)\n        {\n            if (val instanceof ByteBuffer)\n                builder.add((ByteBuffer) val);\n            else\n                builder.add(val);\n        }\n        return builder.build();\n    }\n\n    public int compare(Clusterable c1, Clusterable c2)\n    {\n        return compare((ClusteringPrefix<?>) c1.clustering(), (ClusteringPrefix<?>) c2.clustering());\n    }\n\n    public <V1, V2> int compare(ClusteringPrefix<V1> c1, ClusteringPrefix<V2> c2)","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/ClusteringComparator.java#L107-L143","documentation":"ClusteringComparator.make() builds a Clustering from a varargs list of component values and enforces that the number of supplied values equals the number of clustering columns. This is an internal invariant check, thrown as IllegalArgumentException, typically a programming bug in internal code or tooling rather than a user-facing CQL error.","triggerScenarios":"Calling ClusteringComparator.make(v1, v2) on a table with a different number of clustering columns; programmatic row construction (compaction, repairs, tools, tests) with the wrong arity.","commonSituations":"Custom utilities/tests that hardcode clustering arity; schema changes adding clustering columns while old code still builds 1-component clusterings.","solutions":["Pass exactly size() values (the table's clustering column count) to make().","Derive the value count from the comparator/schema instead of hardcoding.","Use CBuilder or the appropriate helper that handles partial clustering prefixes when applicable."],"exampleFix":"// before\nClustering<?> c = comparator.make(partitionKeyValue); // table has 2 clustering columns\n// after\nClustering<?> c = comparator.make(clusteringVal1, clusteringVal2);","handlingStrategy":"type-guard","validationCode":"if (values.length != comparator.size())\n    throw new IllegalArgumentException(\"Expected \" + comparator.size() + \" clustering components, got \" + values.length);","typeGuard":"boolean hasValidArity(ClusteringComparator c, Object... vals) { return vals.length == c.size(); }","tryCatchPattern":"try { Clustering<?> cl = comparator.make(values); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Invalid number of components\")) deriveArityFromSchema(); else throw e; }","preventionTips":["Derive clustering arity from the schema, never hardcode","Update tooling/tests after adding clustering columns","Prefer CBuilder for partial prefixes"],"tags":["internal","clustering","invariant"],"backgroundTag":"internal-invariant-violation","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"}