{"record":{"id":"362130c1f01d5174","repo":"apache/beam","slug":"the-confidence-must-be-between-0-and-1","errorCode":null,"errorMessage":"The confidence must be between 0 and 1","messagePattern":"The confidence must be between 0 and 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sketching/src/main/java/org/apache/beam/sdk/extensions/sketching/SketchFrequencies.java","lineNumber":387,"sourceCode":"    }\n\n    /**\n     * Returns a new {@link CountMinSketchFn} combiner with new precision accuracy parameters {@code\n     * epsilon} and {@code confidence}.\n     *\n     * <p>Keep in mind that the lower the {@code epsilon} value, the greater the width, and the\n     * greater the confidence, the greater the depth.\n     *\n     * @param epsilon the error relative to the total number of distinct elements\n     * @param confidence the confidence in the result to not exceed the relative error\n     */\n    public CountMinSketchFn<InputT> withAccuracy(double epsilon, double confidence) {\n      if (epsilon <= 0D) {\n        throw new IllegalArgumentException(\"The relative error must be positive\");\n      }\n\n      if (confidence <= 0D || confidence >= 1D) {\n        throw new IllegalArgumentException(\"The confidence must be between 0 and 1\");\n      }\n      return new CountMinSketchFn<>(inputCoder, epsilon, confidence);\n    }\n\n    @Override\n    public Sketch<InputT> createAccumulator() {\n      return Sketch.create(epsilon, confidence);\n    }\n\n    @Override\n    public Sketch<InputT> addInput(Sketch<InputT> accumulator, InputT element) {\n      accumulator.add(element, inputCoder);\n\n      return accumulator;\n    }\n\n    @Override\n    public Sketch<InputT> mergeAccumulators(Iterable<Sketch<InputT>> accumulators) {","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sketching/src/main/java/org/apache/beam/sdk/extensions/sketching/SketchFrequencies.java#L369-L405","documentation":"SketchFrequencies.CountMinSketchFn.withAccuracy validates the confidence level; it must lie strictly between 0 and 1 because it represents a probability that the relative error bound holds (the sketch depth derives from ln(1/(1-confidence))). A confidence of 0, 1, or outside this range throws this IllegalArgumentException.","triggerScenarios":"Calling withAccuracy(epsilon, 1) or withAccuracy(epsilon, 0), or passing a percentage like 99 instead of 0.99, or a config value misparsed as 0.","commonSituations":"Users passing confidence as a percentage (99, 99.9) rather than a fraction (0.99, 0.999); config/flag defaults of 0 when unset; confusion between fraction and percent conventions.","solutions":["Pass a fraction strictly between 0 and 1, e.g. withAccuracy(0.01, 0.999).","If your config stores percentages, divide by 100 before calling withAccuracy.","Add a pre-check on config values (0 < confidence < 1) before constructing the transform."],"exampleFix":"// before\nsketch.withAccuracy(0.01, 99); // throws: 99 is not a fraction\n// after\nsketch.withAccuracy(0.01, 0.99);","handlingStrategy":"validation","validationCode":"if (!(confidence > 0D && confidence < 1D)) throw new IllegalArgumentException(\"confidence must be in (0,1), got \" + confidence);","typeGuard":null,"tryCatchPattern":"try { sketch.withAccuracy(eps, conf); } catch (IllegalArgumentException e) { /* correct units or use defaults */ }","preventionTips":["Convert percentages to fractions (99 -> 0.99) before calling","Validate flag/config defaults are non-zero","Document confidence as a probability in config schemas"],"tags":["java","beam","sketching","count-min-sketch","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}