apache/flink · error · UnsupportedOperationException

The accumulator object '{name}' was created with two differe

Error message

The accumulator object '{name}' was created with two different classes: {first} and {second} Both have the same type ({first.getName()}) but different classloaders: {first.getClassLoader()} and {second.getClassLoader()}

What it means

Thrown by AccumulatorHelper.compareAccumulatorTypes when two accumulators share a name and have the same fully-qualified class name, but were loaded by different ClassLoaders. Same name + same class but different loader means the JVM treats them as distinct types and they cannot be merged. This is a classloader-isolation symptom, not a programming typo.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/accumulators/AccumulatorHelper.java:113

    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: "
                                + first.getClassLoader()
                                + " and "
                                + second.getClassLoader());
            }
        }
    }

    /** Transform the Map with accumulators into a Map containing only the results. */
    public static Map<String, OptionalFailure<Object>> toResultMap(

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Do not bundle flink runtime/accumulator classes inside your user jar; mark them as provided scope.
  2. Ensure the accumulator class is loaded by a single classloader — put it in the user-jar only, or in lib/ only, not both.
  3. If using the planner, avoid registering custom accumulator types across the planner/user boundary.

Example fix

// before (pom.xml - bundles flink classes into fat jar)
<dependency>
  <groupId>org.apache.flink</groupId>
  <artifactId>flink-runtime</artifactId>
</dependency>
// after
<dependency>
  <groupId>org.apache.flink</groupId>
  <artifactId>flink-runtime</artifactId>
  <scope>provided</scope>
</dependency>
Defensive patterns

Strategy: validation

Validate before calling

// ensure flink deps are 'provided' in the user jar
// <scope>provided</scope> on flink-runtime, flink-core, etc.

Prevention

When it happens

Trigger: User-function jars loaded by different classloaders each registering the same accumulator class; the table-planner child classloader vs the user-code classloader both contributing accumulator results; UDFs packaged in nested jars loaded via the user-code classloader mechanism.

Common situations: Running with the planner in a child classloader (flink-table-planner-loader) where accumulator classes leak across the boundary; bundling Flink dependencies inside the user jar (fat-jar) causing duplicate class copies; library conflicts between connector jars and the dist.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/c38ed27d058c41e6. Report an issue: GitHub.