apache/cassandra · error · IllegalArgumentException

Invalid datacenter:rack -

Error message

Invalid datacenter:rack -  

What it means

Location.fromString parses a 'datacenter:rack' string into a Location. It throws IllegalArgumentException when the value contains no ':' separator, i.e. fewer than 2 parts after splitting. The library requires both datacenter and rack to be explicitly encoded in the string to build a valid node placement.

Solutions

  1. Ensure the string is in 'datacenter:rack' form, e.g. "dc1:rack1"
  2. If the rack is unknown, explicitly supply a default rack name (e.g. "datacenter1:rack1") before calling fromString
  3. Check the JSON source feeding fromJSONObject for a truncated or missing ':rack' segment
  4. Validate with a regex like ^[^:]+:[^:]+$ before calling fromString

Example fix

// before
Location loc = Location.fromString("datacenter1");
// after
Location loc = Location.fromString("datacenter1:rack1");
Defensive patterns

Strategy: validation

Validate before calling

if (value == null || !value.matches("[^:]+:[^:]+")) throw new IllegalArgumentException("Expected datacenter:rack, got: " + value);

Type guard

boolean isValidLocationString(String v) { return v != null && v.split(":").length >= 2; }

Try / catch

try { Location loc = Location.fromString(value); } catch (IllegalArgumentException e) { // fall back to a default dc:rack or surface a config error }

Prevention

When it happens

Trigger: Calling Location.fromString(value) or Location.fromJSONObject(...) with a string lacking a colon, e.g. "dc1" instead of "dc1:rack1", or with a null/empty-free string that has only a datacenter.

Common situations: Hand-edited cluster metadata JSON or system properties where the rack portion was omitted; tooling that serializes only the datacenter; copy-paste of a datacenter name from configs that treat rack as optional.

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/fe06cfa8d6c322c7. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/tcm/membership/Location.java:77

    public int hashCode()
    {
        return Objects.hash(datacenter, rack);
    }

    @Override
    public String toString()
    {
        return datacenter + '/' + rack;
    }

    public static Location fromString(String value)
    {
        if (value == null || value.isEmpty())
            return null;

        String[] parts = value.split(":");
        if (parts.length < 2)
            throw new IllegalArgumentException("Invalid datacenter:rack -  " + value);
        else
            return new Location(parts[0].trim(), parts[1].trim());
    }

    public static class Serializer implements MetadataSerializer<Location>
    {
        public void serialize(Location t, DataOutputPlus out, Version version) throws IOException
        {
            out.writeUTF(t.datacenter);
            out.writeUTF(t.rack);
        }

        public Location deserialize(DataInputPlus in, Version version) throws IOException
        {
            return new Location(in.readUTF(), in.readUTF());
        }

        public long serializedSize(Location t, Version version)

View on GitHub (pinned to 88fd0f6a0e)