{"record":{"id":"dd1deeb8084df284","repo":"apache/iceberg","slug":"duplicate-id-id","errorCode":null,"errorMessage":"Duplicate id: ${id}","messagePattern":"Duplicate id: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/CompareSchemasVisitor.java","lineNumber":284,"sourceCode":"      if (listField != null) {\n        return listField.type().asListType().fields().get(0).fieldId();\n      }\n\n      return null;\n    }\n  }\n\n  public enum Result {\n    SAME(0),\n    DATA_CONVERSION_NEEDED(1),\n    SCHEMA_UPDATE_NEEDED(2);\n\n    private static final Map<Integer, Result> BY_ID = Maps.newHashMap();\n\n    static {\n      for (Result e : Result.values()) {\n        if (BY_ID.put(e.id, e) != null) {\n          throw new IllegalArgumentException(\"Duplicate id: \" + e.id);\n        }\n      }\n    }\n\n    private final int id;\n\n    Result(int id) {\n      this.id = id;\n    }\n\n    private Result merge(Result other) {\n      return BY_ID.get(Math.max(this.id, other.id));\n    }\n  }\n}\n","sourceCodeStart":266,"sourceCodeEnd":300,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/CompareSchemasVisitor.java#L266-L300","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Assign a unique integer id to the newly added Result enum constant","Search the enum for all constants and list their ids to find the collision before reassigning"],"exampleFix":"// before\nNEW_RESULT(3),\nOTHER_RESULT(3);\n// after\nNEW_RESULT(3),\nOTHER_RESULT(4);","handlingStrategy":"validation","validationCode":"// Not triggerable by library users; verify enum ids before build\nSet<Integer> ids = new HashSet<>();\nfor (Result r : Result.values()) {\n  if (!ids.add(r.id)) throw new IllegalStateException(\"Duplicate id: \" + r.id);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give each new enum constant a fresh, unique id; never copy-paste a constant without changing the id","Add a unit test asserting all Result ids are distinct"],"tags":["java","enum","internal-invariant"],"backgroundTag":"invalid-enum-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}