apache/cassandra · error · InvalidTypeException

Malformed tuple value

Error message

Malformed tuple value "%s", missing closing ')'

What it means

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.

Solutions

  1. Append the missing ')': ensure the literal is "(1, 2)".
  2. Count parentheses (accounting for quotes) before parsing; reject unbalanced input.
  3. Check upstream pipelines (CSV parsers, log scrapers) for truncation or line-splitting of long values.
  4. Construct TupleValue programmatically to avoid literal syntax entirely.

Example fix

// before
TupleValue v = tupleType.parse("(1, 2");
// after
TupleValue v = tupleType.parse("(1, 2)");
Defensive patterns

Strategy: validation

Validate before calling

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");

Try / catch

try { return tupleType.parse(lit); } catch (InvalidTypeException e) { if (e.getMessage().contains("missing closing")) return repairAndParse(lit); throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: CSV/ETL ingestion truncating long literal rows; copy-paste from logs losing the tail; scripted literal generation with unbalanced parentheses.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/40d24c21b84fce7f. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2996

                }

                String input = value.substring(idx, n);
                v = parseAndSetField(input, v, i);
                idx = n;
                i += 1;

                idx = ParseUtils.skipSpaces(value, idx);
                if (value.charAt(idx) == ')') return v;
                if (value.charAt(idx) != ',')
                    throw new InvalidTypeException(
                    String.format(
                    "Cannot parse tuple value from \"%s\", at character %d expecting ',' but got '%c'",
                    value, idx, value.charAt(idx)));
                ++idx; // skip ','

                idx = ParseUtils.skipSpaces(value, idx);
            }
            throw new InvalidTypeException(
            String.format("Malformed tuple value \"%s\", missing closing ')'", value));
        }

        /**
         * Return a new instance of {@code T}.
         *
         * @return A new instance of {@code T}.
         */
        protected abstract T newInstance();

        /**
         * Serialize an individual field in an object, as part of serializing the whole object to a CQL
         * tuple (see {@link #serialize(Object, ProtocolVersion)}).
         *
         * @param source          The object to read the field from.
         * @param index           The index of the field.
         * @param protocolVersion The protocol version to use.
         * @return The serialized field, or {@code null} if that field should be ignored.

View on GitHub (pinned to 88fd0f6a0e)