{"record":{"id":"2b320c49f9af39f2","repo":"apache/cassandra","slug":"invalid-number-of-values-expecting-d-but-got-d","errorCode":null,"errorMessage":"Invalid number of values. Expecting %d but got %d","messagePattern":"Invalid number of values\\. Expecting (.+?) but got (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TupleType.java","lineNumber":106,"sourceCode":"\n    /**\n     * Returns a new value for this tuple type that uses the provided values for the components.\n     *\n     * <p>The numbers of values passed to this method must correspond to the number of components in\n     * this tuple type. The {@code i}th parameter value will then be assigned to the {@code i}th\n     * component of the resulting tuple value.\n     *\n     * @param values the values to use for the component of the resulting tuple.\n     * @return a new tuple values based on the provided values.\n     * @throws IllegalArgumentException if the number of {@code values} provided does not correspond\n     *                                  to the number of components in this tuple type.\n     * @throws InvalidTypeException     if any of the provided value is not of the correct type for the\n     *                                  component.\n     */\n    public TupleValue newValue(Object... values)\n    {\n        if (values.length != types.size())\n            throw new IllegalArgumentException(\n            String.format(\n            \"Invalid number of values. Expecting %d but got %d\", types.size(), values.length));\n\n        TupleValue t = newValue();\n        for (int i = 0; i < values.length; i++)\n        {\n            DataType dataType = types.get(i);\n            if (values[i] == null) t.setValue(i, null);\n            else\n                t.setValue(\n                i, codecRegistry.codecFor(dataType, values[i]).serialize(values[i], protocolVersion));\n        }\n        return t;\n    }\n\n    @Override\n    public boolean isFrozen()\n    {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TupleType.java#L88-L124","documentation":"TupleType.newValue(Object...) builds a CQL tuple value and requires exactly one argument per component type defined in the tuple. This IllegalArgumentException is thrown when the number of supplied values differs from types.size(). CQL tuples are fixed-arity, so the arity mismatch is rejected before any per-component type check happens.","triggerScenarios":"Calling tupleType.newValue(v1, v2) on a 3-component tuple type, or passing a single array/list of values as one varargs element (e.g. newValue(list) instead of newValue(list.toArray())).","commonSituations":"Schema drift after an ALTER TYPE adding a tuple component, generating values from a metadata-driven loop whose size differs from the tuple definition, or forgetting to spread a collection into varargs.","solutions":["Check tupleType.getComponentTypes().size() and supply exactly that many arguments","Re-read cluster metadata if the schema changed and your cached TupleType is stale","Spread collection values: newValue(list.toArray()) for a tuple matching the list size","Use TupleType.newValue() (empty) plus per-index setters if values are optional"],"exampleFix":"// before\nTupleValue v = tupleType.newValue(values); // values is a List -> counted as 1 arg\n// after\nTupleValue v = tupleType.newValue(values.toArray());","handlingStrategy":"validation","validationCode":"static TupleValue safeNewValue(TupleType tt, Object... values) {\n  int expected = tt.getComponentTypes().size();\n  if (values.length != expected)\n    throw new IllegalArgumentException(\"need \" + expected + \" values, got \" + values.length);\n  return tt.newValue(values);\n}","typeGuard":"static boolean matchesArity(TupleType tt, Object[] values) {\n  return values.length == tt.getComponentTypes().size();\n}","tryCatchPattern":"try {\n  TupleValue v = tupleType.newValue(values);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Invalid number of values\")) {\n    // re-fetch schema metadata or fix arity\n  }\n}","preventionTips":["Spread collections with toArray() instead of passing the collection itself","Refresh TupleType metadata after schema ALTERs","Assert arity equals getComponentTypes().size() before constructing values"],"tags":["cassandra","tuple","arity-mismatch"],"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"}