{"record":{"id":"f239eb02f9970fa5","repo":"apache/cassandra","slug":"invalid-number-of-arguments-expecting-d-values-b-f239eb","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":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java","lineNumber":259,"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     * insertion statement used when creating by this writer) as binary.\n     * @return this writer.\n     */\n    public StressCQLSSTableWriter 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 = insert.buildPartitionKeyNames(options, state);\n        SortedSet<Clustering<?>> clusterings = insert.createClustering(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(insert.metadata(),\n                                                               ClientState.forInternalCalls(),\n                                                               options,\n                                                               insert.getTimestamp(TimeUnit.MILLISECONDS.toMicros(now), options),\n                                                               (int) TimeUnit.MILLISECONDS.toSeconds(now),\n                                                               insert.getTimeToLive(options),\n                                                               null);\n\n        try","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java#L241-L277","documentation":"StressCQLSSTableWriter.rawAddRow(List<ByteBuffer>) binds the provided values to the bound variables of the prepared INSERT statement. It throws InvalidRequestException when the number of supplied values does not exactly match the number of bind variables in the INSERT statement. The expected and actual counts are included in the message.","triggerScenarios":"Calling rawAddRow(values) where values.size() != boundNames.size(), i.e. providing fewer or more ByteBuffers than the '?' placeholders in the using() INSERT statement.","commonSituations":"Schema changed (column added/removed) but the value-building code was not updated; accidentally passing a row with nulls omitted; off-by-one when concatenating key and column values.","solutions":["Count the '?' placeholders in your INSERT statement and match the list size exactly.","Rebuild the values list from the table schema to ensure column order/count alignment.","Add an assertion before the call comparing values.size() against the known bind count.","Use the Map/Object[]-based addRow variants that bind by name instead of position."],"exampleFix":"// before\nwriter.rawAddRow(Arrays.asList(key, col1)); // INSERT has 3 bind variables\n// after\nwriter.rawAddRow(Arrays.asList(key, col1, col2));","handlingStrategy":"validation","validationCode":"// values built per row\nList<ByteBuffer> values = buildRow();\nif (values.size() != expectedBindCount) throw new IllegalArgumentException(\"expected \" + expectedBindCount + \" got \" + values.size());\nwriter.rawAddRow(values);","typeGuard":null,"tryCatchPattern":"try { writer.rawAddRow(values); }\ncatch (InvalidRequestException e) {\n    // message contains expected vs actual counts; log the row for inspection\n    throw new IllegalArgumentException(\"row shape mismatch: \" + e.getMessage(), e);\n}","preventionTips":["Keep a constant for the bind-variable count next to the INSERT string.","Derive values from the table schema, not hand-written lists.","Prefer Map-based addRow to bind by column name.","Update value-building code together with schema changes."],"tags":["sstable","arguments","validation"],"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-17T15:17:12.973Z"}