Skip to content

Conversation

@BewareMyPower
Copy link
Contributor

@BewareMyPower BewareMyPower commented May 2, 2025

Fixes #486

Motivation

The emplace method of SynchronizedHashMap adopts the same semantics as https://en.cppreference.com/w/cpp/container/map/emplace, which inserts the key-value only when the key does not exist. TableViewImpl leverages this method to update the key-values, so it will never succeed. In addition, this method is not thread safe because if the key exists, an iterator will be returned to the caller, then the caller could use the iterator to modify the value without any synchronization.

Modifications

Add two new methods putIfAbsent and put and remove the emplace method.

  • putIfAbsent: inserts the key-value only when the key does not exist and return the optional existing value
  • put: inserts the key-value no matter if the key exists.

Then, replace the emplace call with put in TableViewImpl.

Verifying this change

testSimpleTableView is improved to verify the update case.

@BewareMyPower BewareMyPower self-assigned this May 2, 2025
@BewareMyPower BewareMyPower added bug Something isn't working release/3.7.1 labels May 2, 2025
@BewareMyPower BewareMyPower force-pushed the bewaremypower/tableview-update branch from f8d2c2e to 04e5324 Compare May 2, 2025 12:10
@BewareMyPower BewareMyPower merged commit d9dd029 into apache:main May 4, 2025
13 checks passed
@BewareMyPower BewareMyPower deleted the bewaremypower/tableview-update branch May 4, 2025 08:47
BewareMyPower added a commit that referenced this pull request May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] TableView's existing value will never update

2 participants