{"record":{"id":"1c0b506131471318","repo":"apache/cassandra","slug":"invalid-number-of-arguments-expecting-d-values-b","errorCode":null,"errorMessage":"Invalid number of arguments, expecting %d values but got %d","messagePattern":"Invalid number of arguments, expecting (.+?) values but got (.+?)","errorType":"validation","errorClass":"org.apache.cassandra.cql3.InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java","lineNumber":280,"sourceCode":"    throws InvalidRequestException, IOException\n    {\n        return rawAddRow(Arrays.asList(values));\n    }\n\n    /**\n     * Adds a new row to the writer given already serialized values.\n     * <p>\n     * This is a shortcut for {@code rawAddRow(Arrays.asList(values))}.\n     *\n     * @param values the row values (corresponding to the bind variables of the\n     *               modification statement used when creating by this writer) as binary.\n     * @return this writer.\n     */\n    public CQLSSTableWriter rawAddRow(List<ByteBuffer> values)\n    throws InvalidRequestException, IOException\n    {\n        if (values.size() != boundNames.size())\n            throw new InvalidRequestException(String.format(\"Invalid number of arguments, expecting %d values but got %d\", boundNames.size(), values.size()));\n\n        QueryOptions options = QueryOptions.forInternalCalls(null, values);\n        ClientState state = ClientState.forInternalCalls();\n        List<ByteBuffer> keys = modificationStatement.buildPartitionKeyNames(options, state);\n\n        long now = currentTimeMillis();\n        // Note that we asks indexes to not validate values (the last 'false' arg below) because that triggers a 'Keyspace.open'\n        // and that forces a lot of initialization that we don't want.\n        RowUpdateBuilder builder = new RegularRowUpdateBuilder(modificationStatement.metadata,\n                                                               ClientState.forInternalCalls(),\n                                                               options,\n                                                               modificationStatement.getTimestamp(TimeUnit.MILLISECONDS.toMicros(now), options),\n                                                               options.getNowInSec((int) TimeUnit.MILLISECONDS.toSeconds(now)),\n                                                               modificationStatement.getTimeToLive(options),\n                                                               null);\n\n        try\n        {","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java#L262-L298","documentation":"Thrown by CQLSSTableWriter.rawAddRow(List<ByteBuffer>) as an InvalidRequestException when the provided value list does not contain exactly one value per bound variable in the INSERT/UPDATE statement. The writer validates the count against boundNames before building QueryOptions, because a missing or extra value cannot be bound to the prepared modification statement.","triggerScenarios":"rawAddRow(List<ByteBuffer>) or rawAddRow(Object...) is called with fewer or more values than the number of '?' placeholders in the USING/INSERT statement supplied via using().","commonSituations":"Adding or removing a column in the schema/insert statement but forgetting to update the row data arrays; building rows programmatically where a null column is skipped instead of passed as null; positional confusion after adding a clustering column.","solutions":["Count the bound variables in your INSERT/UPDATE statement and match the list size exactly","Pass null (a null element in the list) for optional columns instead of omitting the element","Regenerate row-building code after any schema or statement change","Use rawAddRow(String, List) or Map-based addToRow variants that are less positional-error-prone"],"exampleFix":"// before\nwriter.rawAddRow(Arrays.asList(key, col1)); // statement binds 3 values\n// after\nwriter.rawAddRow(Arrays.asList(key, col1, col2)); // null for missing, not omitted","handlingStrategy":"validation","validationCode":"List<ByteBuffer> vals = ...; if (vals.size() != expectedBoundCount) throw new IllegalArgumentException(\"expected \" + expectedBoundCount + \" values, got \" + vals.size());","typeGuard":"null","tryCatchPattern":"try { writer.rawAddRow(values); } catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"Invalid number of arguments\")) { /* fix row arity */ } throw e; }","preventionTips":["Keep a constant listing bound variables and derive row lists from it","Pass null elements for skipped columns rather than omitting them","Re-run a smoke insert after any schema or INSERT statement change","Prefer rawAddRow(Map) so column-to-value binding is explicit"],"tags":["sstable","bulk-loading","validation","argument-count"],"backgroundTag":"missing-required-argument","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"}