Skip to content

Fix top ten ordering: replace LinkedHashMap with ConcurrentHashMap for thread safety#403

Merged
tastybento merged 2 commits intodevelopfrom
copilot/fix-top-ten-order
Mar 2, 2026
Merged

Fix top ten ordering: replace LinkedHashMap with ConcurrentHashMap for thread safety#403
tastybento merged 2 commits intodevelopfrom
copilot/fix-top-ten-order

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

Top ten leaderboard displays islands in wrong order — e.g., level 65 in 1st place, level 1065 in 6th. The sorting logic in calculateTopTen() is correct, but the underlying TopTenData.topTen map is a LinkedHashMap concurrently mutated from async threads (loadTopTens, setIslandResults) and read/modified from the main thread (getTopTen, createAndCleanRankings). This corrupts LinkedHashMap's internal doubly-linked list, producing incorrect iteration results that the downstream sort operates on. A server restart does not fix this — the same race re-occurs during async loadTopTens() repopulation.

Changes

  • TopTenData: LinkedHashMapConcurrentHashMap. Insertion order is irrelevant here since calculateTopTen() always sorts into a fresh LinkedHashMap.
  • LevelsManager.addToTopTen(): Invalidate the 1-second sorted cache via cache.remove(world) on level updates, matching the existing pattern in removeEntry().
  • LevelsManagerTest: Added testGetTopTenSortOrder() covering the reported scenario (mixed insertion order, verifies descending output).
Original prompt

This section details on the original issue you should resolve

<issue_title>Top Ten not showing right order</issue_title>
<issue_description>### Expected behavior

Team with higher levels should be higher in the top ten.

Observed/Actual behavior

Image In this example, oofxjonthan's team made up of the members: * Neetje2011 * offxjonathan * debestepanda * sliv0vitz Is listed in 1st place with a level of 65.

However, TechM's team made up of:

  • TechM
  • EpicTechM
  • darkboy5

has a level of 1065 but is listed in 6th place.

Steps/models to reproduce

The adminfreported this as the current state on their server.

BentoBox version

Unknown right now, but assume latest.

Plugin list

No response

Other

The admin is asking how to get the top ten sorted correctly.</issue_description>

<agent_instructions>Focus on how this could occur as much as any potential fix. There may be a legitimate scenario where this could happen, but it doesn't look likely. If more information is needed from the admin, ask for it.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…alidate cache on update

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect order in top ten standings Fix top ten ordering: use ConcurrentHashMap for thread-safe access Mar 2, 2026
Copilot AI changed the title Fix top ten ordering: use ConcurrentHashMap for thread-safe access Fix top ten ordering: replace LinkedHashMap with ConcurrentHashMap for thread safety Mar 2, 2026
@tastybento tastybento marked this pull request as ready for review March 2, 2026 01:44
@tastybento tastybento merged commit 9c535c5 into develop Mar 2, 2026
2 checks passed
@tastybento tastybento deleted the copilot/fix-top-ten-order branch March 2, 2026 01:44
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 2, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Top Ten not showing right order

2 participants