apache/cassandra · error · ConfigurationException

MapType takes exactly 2 type parameters

Error message

MapType takes exactly 2 type parameters

What it means

MapType.getInstance(TypeParser) builds a MapType from parsed type parameters, e.g. map<keyType, valueType>. It throws ConfigurationException when the parser did not supply exactly two type parameters, since a map needs both a key type and a value type.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/MapType.java:69

import org.apache.cassandra.utils.bytecomparable.ByteSource;
import org.apache.cassandra.utils.bytecomparable.ByteSourceInverse;

public class MapType<K, V> extends CollectionType<Map<K, V>>
{
    // interning instances
    private static final ConcurrentHashMap<Pair<AbstractType<?>, AbstractType<?>>, MapType> instances = new ConcurrentHashMap<>();
    private static final ConcurrentHashMap<Pair<AbstractType<?>, AbstractType<?>>, MapType> frozenInstances = new ConcurrentHashMap<>();

    private final AbstractType<K> keys;
    private final AbstractType<V> values;
    private final MapSerializer<K, V> serializer;
    private final boolean isMultiCell;

    public static MapType<?, ?> getInstance(TypeParser parser) throws ConfigurationException, SyntaxException
    {
        List<AbstractType<?>> l = parser.getTypeParameters();
        if (l.size() != 2)
            throw new ConfigurationException("MapType takes exactly 2 type parameters");

        return getInstance(l.get(0).freeze(), l.get(1).freeze(), true);
    }

    public static <K, V> MapType<K, V> getInstance(AbstractType<K> keys, AbstractType<V> values, boolean isMultiCell)
    {
        ConcurrentHashMap<Pair<AbstractType<?>, AbstractType<?>>, MapType> internMap = isMultiCell ? instances : frozenInstances;
        Pair<AbstractType<?>, AbstractType<?>> p = Pair.create(keys, values);
        MapType<K, V> t = internMap.get(p);
        return null == t
             ? internMap.computeIfAbsent(p, k -> new MapType<>(k.left, k.right, isMultiCell))
             : t;
    }

    private MapType(AbstractType<K> keys, AbstractType<V> values, boolean isMultiCell)
    {
        super(ComparisonType.CUSTOM, Kind.MAP);
        this.keys = keys;

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Supply exactly two type parameters: e.g. map<org.apache.cassandra.db.marshal.Int32Type,org.apache.cassandra.db.marshal.UTF8Type>.
  2. Validate the type string before parsing with TypeParser; count the '<...>' parameters for map types.
  3. Catch ConfigurationException around TypeParser.parse()/getInstance and surface a clear schema-definition message to the user.

Example fix

// before
TypeParser.parse("org.apache.cassandra.db.marshal.MapType(org.apache.cassandra.db.marshal.Int32Type)");
// after
TypeParser.parse("org.apache.cassandra.db.marshal.MapType(org.apache.cassandra.db.marshal.Int32Type,org.apache.cassandra.db.marshal.UTF8Type)");
Defensive patterns

Strategy: validation

Validate before calling

List<AbstractType<?>> params = parser.getTypeParameters();
if (params.size() != 2)
    throw new ConfigurationException("map type requires exactly 2 parameters, got " + params.size());

Try / catch

try {
    MapType<?, ?> mt = MapType.getInstance(parser);
} catch (ConfigurationException e) {
    // report malformed map type definition to user
} catch (SyntaxException e) {
    // report unparseable type string
}

Prevention

When it happens

Trigger: Invoking TypeParser.parse() on a comparator/validation string like 'org.apache.cassandra.db.marshal.MapType' with zero, one, or three-plus type parameters, or a type string such as map<int> reaching MapType.getInstance(parser).

Common situations: Hand-written comparator strings in cassandra.yaml or schema definitions with a malformed map type; programmatic type parsing from user-supplied schema strings; typos dropping one of the two map type arguments.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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