Fix IndexOutOfBoundsException in AlternativeCommandsHandler.getAlternative - #6609
Open
minoneer wants to merge 1 commit into
Open
Fix IndexOutOfBoundsException in AlternativeCommandsHandler.getAlternative#6609minoneer wants to merge 1 commit into
minoneer wants to merge 1 commit into
Conversation
…ative getAlternative prunes collected WeakReferences through its own iterator, which can remove every entry in a bucket. The following commands.get(0) then throws IndexOutOfBoundsException. Store the first live alias during the iteration and return that instead, or null when nothing live remains - which the caller already treats as "no alternative". Fixes EssentialsX#6608
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Information
This PR fixes #6608.
Details
Proposed fix:
getAlternativeprunes collectedWeakReferences through its own iterator, which can removeevery entry in a bucket. The following
commands.get(0)then throwsIndexOutOfBoundsException.This stores the first live alias during the iteration and returns that instead, or
nullwhennothing live remains, which is what the caller already tests for
(
getAlternative(label) == nullinEssentialsPlayerListener.CommandSendFilter).Confirmed with an instrumented build that logged the list sizes around the prune loop:
Both references in the
wbucket had been collected and the loop removed both.Note: this does not address the possible concurrent modification also raised in #6608
(
altCommandsis a plainHashMapofArrayList, modified from the async command-send path).That needs a separate synchronisation decision.
Environments tested:
OS: Debian 12
Java version: 25.0.4 2026-07-21 LTS
Demonstration:
Before, on every boot with a player join (5 consecutive boots, EssentialsX 2.22.0 and
2.22.1-dev+17-382de4f, same server and plugin set):
Cause isolated with a temporary instrumented build logging list sizes around the prune loop:
Both
WeakReferencein thewbucket had been collected and the loop removed both.After, with this fix (2.22.1-dev+18), same server, player join: