apache/flink · error · UnsupportedOperationException
The accumulator object '{name}' was created with two differe
Error message
The accumulator object '{name}' was created with two different types: {first.getName()} and {second.getName()} What it means
Thrown by AccumulatorHelper.compareAccumulatorTypes when two accumulators registered under the same name have different Java class names. Flink merges accumulator results from parallel subtasks by name; merging requires both to be the exact same accumulator type (e.g., both IntCounter). Different types cannot be merged, so the framework rejects the combination at result-collection time.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/accumulators/AccumulatorHelper.java:104
Accumulator<V, R> typedToMerge = (Accumulator<V, R>) toMerge;
typedTarget.merge(typedToMerge);
return typedTarget;
}
/** Compare both classes and throw {@link UnsupportedOperationException} if they differ. */
@SuppressWarnings("rawtypes")
public static void compareAccumulatorTypes(
Object name, Class<? extends Accumulator> first, Class<? extends Accumulator> second)
throws UnsupportedOperationException {
if (first == null || second == null) {
throw new NullPointerException();
}
if (first != second) {
if (!first.getName().equals(second.getName())) {
throw new UnsupportedOperationException(
"The accumulator object '"
+ name
+ "' was created with two different types: "
+ first.getName()
+ " and "
+ second.getName());
} else {
// damn, name is the same, but different classloaders
throw new UnsupportedOperationException(
"The accumulator object '"
+ name
+ "' was created with two different classes: "
+ first
+ " and "
+ second
+ " Both have the same type ("
+ first.getName()
+ ") but different classloaders: "View on GitHub (pinned to 2f3c205e92)
Solutions
- Give every accumulator a unique name, or ensure all subtasks that share a name use the identical accumulator class.
- Namespace accumulator names per operator (e.g., 'opA.count', 'opB.count').
- Audit getRuntimeContext().getXxxCounter(...) calls for name collisions across the job.
Example fix
// before
getRuntimeContext().getIntCounter("count"); // operator A
getRuntimeContext().getLongCounter("count"); // operator B -> mismatch
// after
getRuntimeContext().getIntCounter("opA.count");
getRuntimeContext().getLongCounter("opB.count"); Defensive patterns
Strategy: validation
Validate before calling
// use distinct names per accumulator type
getRuntimeContext().getIntCounter("opA.count");
getRuntimeContext().getLongCounter("opB.count"); Prevention
- Give each accumulator a unique, namespaced name.
- Ensure all subtasks sharing a name use the same accumulator class.
- Audit accumulator names during code review.
When it happens
Trigger: Two operators/subtasks registering an accumulator under the same name but with different accumulator classes (e.g., one uses IntCounter, another LongCounter under name 'count'); copy-paste of accumulator names across operators that count different types.
Common situations: Reusing a generic accumulator name like 'count' or 'sum' in unrelated UDFs; library code that registers accumulators with fixed names that collide with user code.
Related errors
- The merged accumulator must be AverageAccumulator.
- Could not stop with a savepoint job "{}".
- Could not stop with a detached savepoint job "{}".
- Failed to trigger a savepoint for the job {}.
- JAR file is not a file: {}
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/62e88de0c001199b.
Report an issue: GitHub.