hashgraph / hedera-services

Crypto, token, consensus, file, and smart contract services for the Hedera public ledger
Apache License 2.0
315 stars 138 forks source link

Harden synchronization in WinTabAddresses.java #16726

Open anthony-swirldslabs opened 4 days ago

anthony-swirldslabs commented 4 days ago

Background The following code:

https://github.com/hashgraph/hedera-services/blob/fddcdfa0c7dc3ab13a990bf7e01f17e4dd2c98ec/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/gui/internal/WinTabAddresses.java#L54-L55

tries to synchronize on a return value of a method, and then calls this same method again to use the return value.

Problems with this code:

  1. If the getPlatforms() ever becomes dynamic and can return different values, then this synchronization can break because after the second call, the code may be working with an object that differs from the one which was locked using the first call.
  2. If an engineer replicates this pattern in another place, then they can run into a similar synchronization problem.

Acceptance criteria