{"record":{"id":"6c9f5d537f6ad064","repo":"apache/beam","slug":"sortorder-with-id-not-found-in-sortorders-map","errorCode":null,"errorMessage":"SortOrder with id {} not found in sortOrders map","messagePattern":"SortOrder with id (.+?) not found in sortOrders map","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/SerializableTableSpec.java","lineNumber":201,"sourceCode":"      synchronized (this) {\n        local = cachedSortOrders;\n        if (local == null) {\n          ImmutableMap.Builder<Integer, SortOrder> builder = ImmutableMap.builder();\n          for (Map.Entry<Integer, String> entry : getSortOrdersJson().entrySet()) {\n            builder.put(entry.getKey(), SortOrderParser.fromJson(getSchema(), entry.getValue()));\n          }\n          cachedSortOrders = local = builder.build();\n        }\n      }\n    }\n    return local;\n  }\n\n  @SchemaIgnore\n  public SortOrder getSortOrder() {\n    SortOrder order = getSortOrders().get(getOrderId());\n    if (order == null) {\n      throw new IllegalStateException(\n          \"SortOrder with id \" + getOrderId() + \" not found in sortOrders map\");\n    }\n    return order;\n  }\n\n  @SchemaIgnore\n  public @Nullable SortOrder getSortOrder(int orderId) {\n    return getSortOrders().get(orderId);\n  }\n\n  @SchemaIgnore\n  public TableIdentifier getTableIdentifier() {\n    TableIdentifier local = cachedTableIdentifier;\n    if (local == null) {\n      synchronized (this) {\n        local = cachedTableIdentifier;\n        if (local == null) {\n          cachedTableIdentifier =","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/SerializableTableSpec.java#L183-L219","documentation":"SerializableTableSpec.getSortOrder() looks up the stored orderId in the serialized sortOrders map and throws IllegalStateException when it is missing. The map snapshots the table's sort orders at serialization time; a miss indicates incomplete/inconsistent serialized state or a sort order that no longer exists in the table.","triggerScenarios":"Calling getSortOrder() when sortOrders lacks the entry for getOrderId() — e.g. the sort order was replaced after serialization, or the object was built without populating sortOrders.","commonSituations":"Sort order replaced via table.replaceSortOrder() between snapshot and use; stale checkpointed state; hand-constructed SerializableTableSpec in tests or tooling that omitted sort orders.","solutions":["Rebuild via SerializableTableSpec.from(table) so sortOrders comes from the table's current sort orders.","Check the table's sortOrders map for the stored order id; fall back to the current sort order if it was replaced.","Refresh the table and re-serialize after any sort order change.","If unsorted (order id 0) is acceptable, treat it explicitly instead of relying on lookup."],"exampleFix":"// before\nlong orderId = spec.getOrderId(); // replaced order, no longer in map\nSortOrder so = spec.getSortOrder();\n// after\nSerializableTableSpec spec = SerializableTableSpec.from(table); // rebuild snapshot before reading sort order","handlingStrategy":"validation","validationCode":"SortOrder so = spec.getSortOrders().get(spec.getOrderId());\nif (so == null) {\n  // sort order replaced — rebuild snapshot from the table\n  spec = SerializableTableSpec.from(table);\n}","typeGuard":null,"tryCatchPattern":"try {\n  SortOrder so = spec.getSortOrder();\n} catch (IllegalStateException e) {\n  // fall back to table.sortOrder() current order\n}","preventionTips":["Rebuild SerializableTableSpec after replaceSortOrder() operations.","Treat unsorted (id 0) explicitly instead of relying on map lookups.","Cover sort-order changes in state round-trip tests."],"tags":["iceberg","java","serialization","sort-order","lookup"],"backgroundTag":"record-not-found","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}