apache/beam · error · UnsupportedOperationException
Override this function to provide the default value.
Error message
Override this function to provide the default value.
What it means
CombineWithContext.Contextful CombineFn's defaultValue() is intentionally unimplemented in the base class; subclasses that can produce a value without context must override it. Calling defaultValue() on a context-aware combine function that does not override it throws UnsupportedOperationException. Beam throws this because the default value cannot be computed without a context implementation supplied by the subclass.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/CombineWithContext.java:127
public AccumT compact(AccumT accumulator, Context c) {
return accumulator;
}
/**
* Applies this {@code CombineFnWithContext} to a collection of input values to produce a
* combined output value.
*/
public OutputT apply(Iterable<? extends InputT> inputs, Context c) {
AccumT accum = createAccumulator(c);
for (InputT input : inputs) {
accum = addInput(accum, input, c);
}
return extractOutput(accum, c);
}
@Override
public OutputT defaultValue() {
throw new UnsupportedOperationException(
"Override this function to provide the default value.");
}
}
}
View on GitHub (pinned to 12126d8942)
Solutions
- Override defaultValue() in your CombineWithContext.CombineFn subclass to return a valid empty-accumulation output.
- Avoid calling defaultValue()/pc.getValue() on results of context-aware combines; guard with isEmpty()/size checks first.
- If the combine has no meaningful default, restructure the pipeline so the default is not required (e.g. use a fallback DoFn).
- Ensure the correct CombineFn base class is used — if no context is needed, extend plain CombineFn which may implement defaultValue.
Example fix
// before
new CombineWithContext.CombineFn<Integer, Integer, Integer>() {
// no defaultValue override
}
// after
new CombineWithContext.CombineFn<Integer, Integer, Integer>() {
@Override public Integer defaultValue() { return 0; }
} Defensive patterns
Strategy: validation
Validate before calling
if (combineFn instanceof CombineWithContext.CombineFn && !overridesDefaultValue(combineFn)) { /* supply default or avoid defaultValue() */ } Try / catch
try { V v = combineFn.defaultValue(); } catch (UnsupportedOperationException e) { V v = fallbackDefault; } Prevention
- Always override defaultValue() in CombineFnWithContext subclasses
- Guard pc.getValue() on empty PCollections with an emptiness check
- Prefer plain CombineFn when no context is needed
When it happens
Trigger: Calling defaultValue() on a CombineFnWithContext (or Contextful-wrapped combine fn) that did not override defaultValue — e.g. reading PCollection.getValue() on an empty (globally windowed) PCollection produced by a context-aware Combine.
Common situations: Calling pc.getValue() on an empty global PCollection produced by Combine.withContext-style transforms; using a custom CombineFnWithContext subclass that skipped the defaultValue override; tests inspecting empty-PCollection values.
Related errors
- Runner does not support draining.
- Unknown DirectoryTreatment: " + directoryTreatment
- Support for move options is not yet implemented.
- %s is for internal use only and does not support case dispat
- Tagged output not supported in FinishBundleContext for Async
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/0c9531bf1f1c09f0.
Report an issue: GitHub.