Skip to content

Suspicious invocation of the 'IEnumerable<T>.Union' method #5862

@VasilievSerg

Description

@VasilievSerg

Hi,
I found the suspicious code via the PVS-Studio analyzer.

Here is the code:

...
case ShardId shardId:
  _shards.Add(shardId); // <=
  return true;
case SnapshotOffer offer when (offer.Snapshot is ShardCoordinator.CoordinatorState state):
  _shards.UnionWith(state.Shards.Keys.Union(state.UnallocatedShards)); // <=
  return true;
case SnapshotOffer offer when (offer.Snapshot is State state):
  _shards.Union(state.Shards); // <=
...

Here is the link to the sources.

Several methods were called for the _shards variable. The last invocation looks suspicious.

Add and UnionWith are methods of the HashSet<T> type. They change the _shards object state. But Union is the extension method which does not change the _shards state. The result of this invocation is not used as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions