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:
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.
If an engineer replicates this pattern in another place, then they can run into a similar synchronization problem.
Acceptance criteria
The getPlatforms() should be called once and the result should be stored in a local variable.
The code should then synchronize on this local variable and use this same variable in the synchronized block, and never call this method the second time.
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:
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.Acceptance criteria
getPlatforms()
should be called once and the result should be stored in a local variable.