Skip to content

Commit

Permalink
Fix MemoryMetadata#streamTableColumnNames
Browse files Browse the repository at this point in the history
The previous implementation returned a lazy iterator over the contents
of the tables map which could throw a ConcurrentModificationException if
another thread modified the map before the caller fully consumed the
iterator. Instead, the iterator returned must be from a fully
materialized collection evaluated fully before returning from the method
and releasing the object monitor.
  • Loading branch information
pettyjamesm authored and ebyhr committed Feb 13, 2023
1 parent 241fc60 commit d1c9d57
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,13 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess
@Override
public synchronized Iterator<TableColumnsMetadata> streamTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
return tables.values().stream()
// This list must be materialized before returning, otherwise the iterator could throw a ConcurrentModificationException
// if another thread modifies the tables map before the iterator is fully consumed
List<TableColumnsMetadata> columnsMetadata = tables.values().stream()
.filter(table -> prefix.matches(table.getSchemaTableName()))
.map(tableInfo -> TableColumnsMetadata.forTable(tableInfo.getSchemaTableName(), tableInfo.getMetadata().getColumns()))
.iterator();
.collect(toImmutableList());
return columnsMetadata.iterator();
}

@Override
Expand Down

0 comments on commit d1c9d57

Please sign in to comment.