{"record":{"id":"55c85a872277a355","repo":"apache/beam","slug":"schema-with-id-not-found-in-schemas-map","errorCode":null,"errorMessage":"Schema with id {} not found in schemas map","messagePattern":"Schema with id (.+?) not found in schemas 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":134,"sourceCode":"      synchronized (this) {\n        local = cachedSchemas;\n        if (local == null) {\n          ImmutableMap.Builder<Integer, Schema> builder = ImmutableMap.builder();\n          for (Map.Entry<Integer, String> entry : getSchemasJson().entrySet()) {\n            builder.put(entry.getKey(), SchemaParser.fromJson(entry.getValue()));\n          }\n          cachedSchemas = local = builder.build();\n        }\n      }\n    }\n    return local;\n  }\n\n  @SchemaIgnore\n  public Schema getSchema() {\n    Schema schema = getSchemas().get(getSchemaId());\n    if (schema == null) {\n      throw new IllegalStateException(\n          \"Schema with id \" + getSchemaId() + \" not found in schemas map\");\n    }\n    return schema;\n  }\n\n  @SchemaIgnore\n  public @Nullable Schema getSchema(int schemaId) {\n    return getSchemas().get(schemaId);\n  }\n\n  @SchemaIgnore\n  public Map<Integer, PartitionSpec> getPartitionSpecs() {\n    Map<Integer, PartitionSpec> local = cachedPartitionSpecs;\n    if (local == null) {\n      synchronized (this) {\n        local = cachedPartitionSpecs;\n        if (local == null) {\n          ImmutableMap.Builder<Integer, PartitionSpec> builder = ImmutableMap.builder();","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/SerializableTableSpec.java#L116-L152","documentation":"SerializableTableSpec.getSchema() looks up the table's current schema id in the serialized schemas map and throws IllegalStateException when it is absent. The schemas map is a snapshot taken from the table at serialization time, so a missing schema id means the serialized spec state is incomplete or inconsistent.","triggerScenarios":"Calling getSchema() on a SerializableTableSpec whose schemas map does not contain getSchemaId() — e.g. a spec built with an inconsistent or truncated schemas map, or deserialized from an older writer that stored a different schema id.","commonSituations":"Schema evolution between serialization and deserialization with a hand-built or stale SerializableTableSpec; corrupted checkpoint state; constructing the object in tests without populating all schemas.","solutions":["Rebuild the SerializableTableSpec from the current table via the standard from(Table) factory instead of hand-constructing it.","Verify the schemas map keys include the schemaId stored on the object.","Refresh the table (table.refresh()) and re-serialize after schema evolution.","Check for mixed connector versions between the code producing and consuming the spec."],"exampleFix":"// before\nSerializableTableSpec spec = new SerializableTableSpec(); // schemas not populated\n// after\nSerializableTableSpec spec = SerializableTableSpec.from(table); // schemas map populated from table.schemas()","handlingStrategy":"validation","validationCode":"Schema schema = spec.getSchemas().get(spec.getSchemaId());\nif (schema == null) {\n  // rebuild from the table instead of proceeding\n  spec = SerializableTableSpec.from(table);\n}","typeGuard":null,"tryCatchPattern":"try {\n  Schema schema = spec.getSchema();\n} catch (IllegalStateException e) {\n  // rebuild spec from the current table and retry once\n}","preventionTips":["Always build SerializableTableSpec with the factory from(Table), not by hand.","Refresh the table after schema evolution before serializing.","Verify schemaId is present in the schemas map in round-trip tests."],"tags":["iceberg","java","serialization","schema","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"}