{"record":{"id":"f982e8834128c480","repo":"apache/cassandra","slug":"invalid-ratio-definition","errorCode":null,"errorMessage":"Invalid ratio definition: ","messagePattern":"Invalid ratio definition: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"tools/stress/src/org/apache/cassandra/stress/settings/OptionRatioDistribution.java","lineNumber":80,"sourceCode":"        delegate = new OptionDistribution(prefix, null, description, required);\n        this.defaultSpec = defaultSpec;\n    }\n\n    @Override\n    public boolean accept(String param)\n    {\n        Matcher m = FULL.matcher(param);\n        if (!m.matches() || !delegate.accept(m.group(1)))\n            return false;\n        divisor = OptionDistribution.parseLong(m.group(2));\n        return true;\n    }\n\n    public static RatioDistributionFactory get(String spec)\n    {\n        OptionRatioDistribution opt = new OptionRatioDistribution(\"\", \"\", \"\", true);\n        if (!opt.accept(spec))\n            throw new IllegalArgumentException(\"Invalid ratio definition: \"+spec);\n        return opt.get();\n    }\n\n    public RatioDistributionFactory get()\n    {\n        if (delegate.setByUser())\n            return new DelegateFactory(delegate.get(), divisor);\n        if (defaultSpec == null)\n            return null;\n        OptionRatioDistribution sub = new OptionRatioDistribution(\"\", null, null, true);\n        if (!sub.accept(defaultSpec))\n            throw new IllegalStateException(\"Invalid default spec: \" + defaultSpec);\n        return sub.get();\n    }\n\n    @Override\n    public boolean happy()\n    {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/stress/settings/OptionRatioDistribution.java#L62-L98","documentation":"OptionRatioDistribution.get(String) is a convenience factory: it builds a fresh OptionRatioDistribution, calls accept(spec) to parse a ratio distribution spec like 'uniform(1..100)/<ratio>', and throws 'Invalid ratio definition: <spec>' if the spec fails to parse. Ratio distributions weight distributions by a ratio value.","triggerScenarios":"Calling OptionRatioDistribution.get() with a malformed spec, e.g. an unknown distribution name, bad bounds, missing ratio denominator, or an empty string.","commonSituations":"Hand-written stress profile weights with typos; using a distribution kind not supported for ratios; missing the '/' ratio part; wrong parameter counts inside parentheses.","solutions":["Use a valid spec format: OptionRatioDistribution.get(\"uniform(1..100)/1\")","Verify the distribution name and its parameters match OptionDistribution syntax","Print/inspect the spec string for hidden whitespace or quotes before parsing."],"exampleFix":"// before\nOptionRatioDistribution.get(\"unifrm(1..100)\");\n// after\nOptionRatioDistribution.get(\"uniform(1..100)/1\");","handlingStrategy":"try-catch","validationCode":"boolean validRatioSpec(String s){ return s.matches(\"(uniform|gaussian|fixed|seq|normal|weibull)\\\\([^)]*\\\\)/\\\\d+(\\\\.\\\\d+)?\"); }","typeGuard":null,"tryCatchPattern":"try { RatioDistributionFactory f = OptionRatioDistribution.get(spec); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(\"Invalid ratio distribution spec '\" + spec + \"': expected <distribution(params)>/<ratio>\", e); }","preventionTips":["Build specs from constants instead of concatenating raw strings","Validate distribution names and parameters against OptionDistribution syntax first","Never pass user input straight into get() without regex validation"],"tags":["cli","argument-validation","distribution"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}