apache/cassandra · error · IllegalArgumentException

set twice

Error message

 set twice

What it means

OptionAnyProbabilities parses weight=probability pairs like read=0.5,write=0.5. If the same option key appears twice, the second put would silently overwrite the first, so the parser detects an existing entry and throws '<key> set twice' IllegalArgumentException instead.

Solutions

  1. Remove the duplicate key, keeping one entry per operation type
  2. De-duplicate programmatically built argument lists before invoking stress
  3. Use distinct keys for distinct operations (read=, write=, counterwrite=, etc.)

Example fix

// before
stress mixed read=0.3,read=0.7,write=0.4
// after
stress mixed read=0.6,write=0.4
Defensive patterns

Strategy: validation

Validate before calling

Map<String,Double> seen = new HashMap<>();
for (String p : probabilityArgs) {
    String[] kv = p.split("=");
    if (seen.putIfAbsent(kv[0], Double.valueOf(kv[1])) != null)
        throw new IllegalArgumentException(kv[0] + " set twice");
}

Try / catch

try { parseOption(param); } catch (IllegalArgumentException e) { log.error("Duplicate option: {}", e.getMessage()); }

Prevention

When it happens

Trigger: Specifying the same probability key twice in a stress command, e.g. stress read read=0.3,read=0.7 or duplicate keys in an options list like -rate threads=10 ... threads=20 handled by this option.

Common situations: Building the stress command programmatically and appending duplicate option strings; concatenating command lines from scripts; typo'd key variants that normalize to the same name.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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

Appendix: source

Thrown at tools/stress/src/org/apache/cassandra/stress/settings/OptionAnyProbabilities.java:50

{
    public OptionAnyProbabilities(String name, String description)
    {
        super(name, description, false);
    }

    final CollectRatios ratios = new CollectRatios();

    private static final class CollectRatios extends Option
    {
        Map<String, Double> options = new LinkedHashMap<>();

        boolean accept(String param)
        {
            String[] args = param.split("=");
            if (args.length == 2 && args[1].length() > 0 && args[0].length() > 0)
            {
                if (options.put(args[0], Double.valueOf(args[1])) != null)
                    throw new IllegalArgumentException(args[0] + " set twice");
                return true;
            }
            return false;
        }

        boolean happy()
        {
            return !options.isEmpty();
        }

        String shortDisplay()
        {
            return null;
        }
        public String getOptionAsString()
        {
            StringBuilder sb = new StringBuilder();
            for (Map.Entry<String, Double> entry : options.entrySet())

View on GitHub (pinned to 88fd0f6a0e)