{"record":{"id":"40d24c21b84fce7f","repo":"apache/cassandra","slug":"malformed-tuple-value-s-missing-closing","errorCode":null,"errorMessage":"Malformed tuple value \"%s\", missing closing ')'","messagePattern":"Malformed tuple value \"(.+?)\", missing closing '\\)'","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":2996,"sourceCode":"                }\n\n                String input = value.substring(idx, n);\n                v = parseAndSetField(input, v, i);\n                idx = n;\n                i += 1;\n\n                idx = ParseUtils.skipSpaces(value, idx);\n                if (value.charAt(idx) == ')') return v;\n                if (value.charAt(idx) != ',')\n                    throw new InvalidTypeException(\n                    String.format(\n                    \"Cannot parse tuple value from \\\"%s\\\", at character %d expecting ',' but got '%c'\",\n                    value, idx, value.charAt(idx)));\n                ++idx; // skip ','\n\n                idx = ParseUtils.skipSpaces(value, idx);\n            }\n            throw new InvalidTypeException(\n            String.format(\"Malformed tuple value \\\"%s\\\", missing closing ')'\", value));\n        }\n\n        /**\n         * Return a new instance of {@code T}.\n         *\n         * @return A new instance of {@code T}.\n         */\n        protected abstract T newInstance();\n\n        /**\n         * Serialize an individual field in an object, as part of serializing the whole object to a CQL\n         * tuple (see {@link #serialize(Object, ProtocolVersion)}).\n         *\n         * @param source          The object to read the field from.\n         * @param index           The index of the field.\n         * @param protocolVersion The protocol version to use.\n         * @return The serialized field, or {@code null} if that field should be ignored.","sourceCodeStart":2978,"sourceCodeEnd":3014,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L2978-L3014","documentation":"The tuple codec's parse loop advances field by field; if the input string is exhausted before a closing ')' is found, this InvalidTypeException is thrown. It means the tuple literal has fewer closing parentheses than opening ones, or the literal simply ends mid-tuple.","triggerScenarios":"Parsing \"(1, 2\" (truncated), a string cut off by a length limit or line-wrap in a config/CSV file, nested tuples where the closing parens of inner tuples unbalanced the count.","commonSituations":"CSV/ETL ingestion truncating long literal rows; copy-paste from logs losing the tail; scripted literal generation with unbalanced parentheses.","solutions":["Append the missing ')': ensure the literal is \"(1, 2)\".","Count parentheses (accounting for quotes) before parsing; reject unbalanced input.","Check upstream pipelines (CSV parsers, log scrapers) for truncation or line-splitting of long values.","Construct TupleValue programmatically to avoid literal syntax entirely."],"exampleFix":"// before\nTupleValue v = tupleType.parse(\"(1, 2\");\n// after\nTupleValue v = tupleType.parse(\"(1, 2)\");","handlingStrategy":"validation","validationCode":"int depth = 0; boolean inStr = false; for (char c : lit.toCharArray()) { if (c=='\\'') inStr=!inStr; else if (!inStr) { if (c=='(') depth++; if (c==')') depth--; } } if (depth != 0) throw new IllegalArgumentException(\"unbalanced parens in tuple literal\");","typeGuard":null,"tryCatchPattern":"try { return tupleType.parse(lit); } catch (InvalidTypeException e) { if (e.getMessage().contains(\"missing closing\")) return repairAndParse(lit); throw e; }","preventionTips":["Validate balanced parentheses outside quotes before parse","Ensure ETL lines are not split on commas inside literals","Prefer programmatic TupleValue construction in pipelines"],"tags":["parsing","tuple","cql-literal","syntax"],"backgroundTag":"invalid-argument-format","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"}