apache/beam · error · IllegalArgumentException
The confidence must be between 0 and 1
Error message
The confidence must be between 0 and 1
What it means
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.
Source
Thrown at sdks/java/extensions/sketching/src/main/java/org/apache/beam/sdk/extensions/sketching/SketchFrequencies.java:387
}
/**
* Returns a new {@link CountMinSketchFn} combiner with new precision accuracy parameters {@code
* epsilon} and {@code confidence}.
*
* <p>Keep in mind that the lower the {@code epsilon} value, the greater the width, and the
* greater the confidence, the greater the depth.
*
* @param epsilon the error relative to the total number of distinct elements
* @param confidence the confidence in the result to not exceed the relative error
*/
public CountMinSketchFn<InputT> withAccuracy(double epsilon, double confidence) {
if (epsilon <= 0D) {
throw new IllegalArgumentException("The relative error must be positive");
}
if (confidence <= 0D || confidence >= 1D) {
throw new IllegalArgumentException("The confidence must be between 0 and 1");
}
return new CountMinSketchFn<>(inputCoder, epsilon, confidence);
}
@Override
public Sketch<InputT> createAccumulator() {
return Sketch.create(epsilon, confidence);
}
@Override
public Sketch<InputT> addInput(Sketch<InputT> accumulator, InputT element) {
accumulator.add(element, inputCoder);
return accumulator;
}
@Override
public Sketch<InputT> mergeAccumulators(Iterable<Sketch<InputT>> accumulators) {View on GitHub (pinned to 12126d8942)
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.
Example fix
// before sketch.withAccuracy(0.01, 99); // throws: 99 is not a fraction // after sketch.withAccuracy(0.01, 0.99);
Defensive patterns
Strategy: validation
Validate before calling
if (!(confidence > 0D && confidence < 1D)) throw new IllegalArgumentException("confidence must be in (0,1), got " + confidence); Try / catch
try { sketch.withAccuracy(eps, conf); } catch (IllegalArgumentException e) { /* correct units or use defaults */ } Prevention
- Convert percentages to fractions (99 -> 0.99) before calling
- Validate flag/config defaults are non-zero
- Document confidence as a probability in config schemas
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- The relative error must be positive
- Coder must be deterministic to perform this sketch.${e.getMe
- The accumulators cannot be merged:${e.getMessage()}
- Pipeline update will not be possible because the following t
- One or more ErrorHandlers aren't closed, and this pipeline c
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/362130c1f01d5174.
Report an issue: GitHub.