apache/cassandra · error · RuntimeException

Malformed target host: ${s}

Error message

Malformed target host: ${s}

What it means

QueryReplayer.fromString splits the target string on '@' and expects either one part (host[:port]) or two (user:password@host[:port]). Any other shape — e.g. multiple '@' characters producing more segments — cannot be parsed, so it throws with the offending string. It is a strict syntax check on the --target argument.

Source

Thrown at tools/fqltool/src/org/apache/cassandra/fqltool/QueryReplayer.java:223

        {
            String [] userInfoHostPort = s.split("@");

            String hostPort = null;
            String user = null;
            String password = null;
            if (userInfoHostPort.length == 2)
            {
                String [] userPassword = userInfoHostPort[0].split(":");
                if (userPassword.length != 2)
                    throw new RuntimeException("Username provided but no password");
                hostPort = userInfoHostPort[1];
                user = userPassword[0];
                password = userPassword[1];
            }
            else if (userInfoHostPort.length == 1)
                hostPort = userInfoHostPort[0];
            else
                throw new RuntimeException("Malformed target host: "+s);

            String[] splitHostPort = hostPort.split(":");
            int port = 9042;
            if (splitHostPort.length == 2)
                port = Integer.parseInt(splitHostPort[1]);

            return new ParsedTargetHost(splitHostPort[0], port, user, password);
        }
    }

    public static interface SessionProvider extends Closeable
    {
        Session connect(String connectionString);
        void close();
    }

    private static final class DefaultSessionProvider implements SessionProvider
    {

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Remove or escape '@' characters inside the username/password, or use credentials without '@'
  2. Ensure the target has at most one '@' separating credentials from host[:port]

Example fix

// before
--target admin@example.com:pw@127.0.0.1
// after
--target admin:pw@127.0.0.1
Defensive patterns

Strategy: validation

Validate before calling

function validateTarget(t) {
  if (t.split('@').length > 2) throw new Error('at most one @ allowed in target: ' + t);
}

Type guard

const wellFormedTarget = t => t.split('@').length <= 2;

Try / catch

try { parseTarget(arg); } catch (RuntimeException e) { if (e.getMessage().startsWith("Malformed target host")) { usage("target format: [user:password@]host[:port]"); } else throw e; }

Prevention

When it happens

Trigger: Passing a --target value containing more than one '@' (e.g. 'us@er:pw@host').

Common situations: Usernames containing '@' (common with email addresses used as credentials); copy-paste errors adding extra '@' characters.

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