Skip to content

fix: ConcurrentModificationException in validateUpgradeTier crashes addon on load#87

Merged
tastybento merged 2 commits into
developfrom
copilot/upgrade-addon-not-loading
Jun 12, 2026
Merged

fix: ConcurrentModificationException in validateUpgradeTier crashes addon on load#87
tastybento merged 2 commits into
developfrom
copilot/upgrade-addon-not-loading

Conversation

Copilot AI commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Addon fails to load when any upgrade tier references a missing upgrade data entry (e.g. after partial seeding or manual data corruption). validateUpgradeTier() called HashMap.remove() inside a values().forEach() loop over the same map, throwing ConcurrentModificationException and aborting the entire addon startup.

Fix

Replace the unsafe iteration+removal pattern with entrySet().removeIf():

// Before — throws ConcurrentModificationException
this.upgradeTierCache.values().forEach(tier -> {
    if (!this.upgradeDataCache.containsKey(tier.getUpgrade())) {
        this.upgradeTierCache.remove(tier.getUniqueId()); // structural mod during iteration
    }
});

// After — safe
this.upgradeTierCache.entrySet().removeIf(entry -> {
    if (!this.upgradeDataCache.containsKey(entry.getValue().getUpgrade())) {
        this.addon.logWarning("Upgrade tier " + entry.getValue().getUniqueId()
            + " has a reference to an unknown upgrade data. It will be skipped");
        return true;
    }
    return false;
});

Also corrects two typos in the warning message (unknowunknown, skipedskipped).

Tests

Adds UpgradesDataManagerTest with three cases: single orphaned tier removed without exception, valid tier preserved, and multiple simultaneous orphans removed — covering the exact reported scenario (Boxed_example_range2_t1, Boxed_example_diamond_t1).

Replace HashMap.values().forEach() + remove() (which throws
ConcurrentModificationException) with entrySet().removeIf(), the
standard safe pattern for removing map entries during iteration.

Also fix typos in the warning message: unknow→unknown, skiped→skipped.

Add UpgradesDataManagerTest covering single orphan removal, valid-tier
preservation, and multiple simultaneous orphans (the exact scenario
reported with Boxed_example_range2_t1 and Boxed_example_diamond_t1).
Copilot AI changed the title [WIP] Fix upgrade addon loading issue and validation errors fix: ConcurrentModificationException in validateUpgradeTier crashes addon on load Jun 11, 2026
Copilot AI requested a review from tastybento June 11, 2026 23:18
@tastybento tastybento marked this pull request as ready for review June 11, 2026 23:19
@sonarqubecloud

Copy link
Copy Markdown

@tastybento tastybento merged commit 1f54dba into develop Jun 12, 2026
3 checks passed
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.

2 participants