apache/iceberg · error · IllegalArgumentException

Duplicate id: ${id}

Error message

Duplicate id: ${id}

What it means

CompareSchemasVisitor's Result enum registers each enum constant in a static BY_ID map keyed by its integer id. If two constants share the same id, the static initializer detects the collision at class-load time and throws this IllegalArgumentException. This is a developer-facing invariant check protecting the compact wire representation of schema-comparison results, not an error end users can trigger.

Source

Thrown at flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/CompareSchemasVisitor.java:284

      if (listField != null) {
        return listField.type().asListType().fields().get(0).fieldId();
      }

      return null;
    }
  }

  public enum Result {
    SAME(0),
    DATA_CONVERSION_NEEDED(1),
    SCHEMA_UPDATE_NEEDED(2);

    private static final Map<Integer, Result> BY_ID = Maps.newHashMap();

    static {
      for (Result e : Result.values()) {
        if (BY_ID.put(e.id, e) != null) {
          throw new IllegalArgumentException("Duplicate id: " + e.id);
        }
      }
    }

    private final int id;

    Result(int id) {
      this.id = id;
    }

    private Result merge(Result other) {
      return BY_ID.get(Math.max(this.id, other.id));
    }
  }
}

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Assign a unique integer id to the newly added Result enum constant
  2. Search the enum for all constants and list their ids to find the collision before reassigning

Example fix

// before
NEW_RESULT(3),
OTHER_RESULT(3);
// after
NEW_RESULT(3),
OTHER_RESULT(4);
Defensive patterns

Strategy: validation

Validate before calling

// Not triggerable by library users; verify enum ids before build
Set<Integer> ids = new HashSet<>();
for (Result r : Result.values()) {
  if (!ids.add(r.id)) throw new IllegalStateException("Duplicate id: " + r.id);
}

Prevention

When it happens

Trigger: Editing the Result enum and adding a constant whose id integer duplicates an existing constant's id; the exception is thrown from the static block the first time the class is loaded.

Common situations: Copying an enum constant line to add a new result code but forgetting to bump the id; merging branches that both allocated the same id value.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/dd1deeb8084df284. Report an issue: GitHub.