{"record":{"id":"d6ede44457194060","repo":"apache/cassandra","slug":"cannot-set-field-to-value-outside-the-ra","errorCode":null,"errorMessage":"Cannot set '\" + field + \"' to value outside the range (0..1]\"","messagePattern":"Cannot set '\" \\+ field \\+ \"' to value outside the range \\(0\\.\\.1\\]\"","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/virtual/AccordDebugKeyspace.java","lineNumber":2508,"sourceCode":"    private static int checkNonNegative(Object value, String field, int ifNull)\n    {\n        if (value == null)\n            return ifNull;\n\n        int v = (Integer)value;\n        if (v < 0)\n            throw new InvalidRequestException(\"Cannot set '\" + field + \"' to negative value\");\n        return v;\n    }\n\n    private static float checkChance(Object value, String field)\n    {\n        if (value == null)\n            return 1.0f;\n\n        float v = (Float)value;\n        if (v <= 0 || v > 1.0f)\n            throw new InvalidRequestException(\"Cannot set '\" + field + \"' to value outside the range (0..1]\");\n        return v;\n    }\n\n    private static <T extends Enum<T>> Set<String> toStrings(TinyEnumSet<T> set, IntFunction<T> lookup)\n    {\n        ImmutableSet.Builder<String> builder = ImmutableSet.builder();\n        for (T t : set.iterable(lookup))\n            builder.add(t.name());\n        return builder.build();\n    }\n\n    private static AccordTracing tracing()\n    {\n        return ((AccordAgent)AccordService.unsafeInstance().agent()).tracing();\n    }\n\n    private static <E extends Enum<E>> E tryParse(Object input, boolean toUpperCase, Class<E> clazz, Function<String, E> valueOf)\n    {","sourceCodeStart":2490,"sourceCodeEnd":2526,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/virtual/AccordDebugKeyspace.java#L2490-L2526","documentation":"checkChance validates a float field representing a probability/sampling chance, defaulting to 1.0f when unset. Only values in the half-open interval (0..1] are legal; 0, negatives, and values > 1 throw this InvalidRequestException.","triggerScenarios":"Setting a chance/probability column on an Accord debug virtual table to 0, a negative number, or any value greater than 1.0 (e.g. SET sample_chance = 0 or = 1.5).","commonSituations":"Trying to disable sampling by setting chance to 0 (not permitted here — use a different toggle if available); entering a percentage like 50 instead of the fraction 0.5; locale/typo issues producing out-of-range numbers.","solutions":["Set the field to a value greater than 0 and at most 1 (e.g. 0.5)","Use 1.0 to sample everything, or omit the column for the default of 1.0","Convert percentages to fractions before writing (50% -> 0.5)"],"exampleFix":"// before\nUPDATE system.accord_debug SET sample_chance = 50;\n// after\nUPDATE system.accord_debug SET sample_chance = 0.5; // fraction in (0..1], not a percentage","handlingStrategy":"validation","validationCode":"if (chance != null && !(chance > 0f && chance <= 1f)) throw new IllegalArgumentException(field + \" must be in (0..1]\");","typeGuard":"boolean isValidChance(Float v) { return v == null || (v > 0f && v <= 1f); }","tryCatchPattern":"try {\n    session.execute(update);\n} catch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"outside the range (0..1]\")) {\n        // resend with chance clamped into (0..1] or omitted for the 1.0 default\n    }\n}","preventionTips":["Express probabilities as fractions, not percentages (50% -> 0.5)","Remember 0 is invalid here; find the intended disable mechanism instead","Clamp parsed floats before writing: Math.max(1e-6f, Math.min(1f, v))"],"tags":["cassandra","cql","validation","range"],"backgroundTag":"value-out-of-range","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"}