Skip to content

Guard against NPE in loadData() when called before onEnable()#509

Merged
tastybento merged 2 commits intodevelopfrom
copilot/fix-aoneblock-reload-error
Apr 26, 2026
Merged

Guard against NPE in loadData() when called before onEnable()#509
tastybento merged 2 commits intodevelopfrom
copilot/fix-aoneblock-reload-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 26, 2026

CraftEngine (and Nexo/ItemsAdder) fire their reload events during server startup before AOneBlock.onEnable() has run, meaning oneBlockManager is still null when loadData() is invoked via the event listener — causing a NullPointerException.

Changes

  • AOneBlock.loadData() — added an early-return null guard for oneBlockManager. When the manager hasn't been initialized yet, loadData() is a no-op; phases load normally during onEnable().
public boolean loadData() {
    if (oneBlockManager == null) {
        // Not yet initialized — phases will load during onEnable()
        return false;
    }
    // ...
}
  • AOneBlockTest — added testLoadDataWhenManagerIsNull to assert that calling loadData() before onEnable() returns false without throwing.

Copilot AI linked an issue Apr 26, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix AOneBlock error on server reload Guard against NPE in loadData() when called before onEnable() Apr 26, 2026
Copilot AI requested a review from tastybento April 26, 2026 19:41
@tastybento tastybento marked this pull request as ready for review April 26, 2026 19:42
@tastybento tastybento merged commit 3272242 into develop Apr 26, 2026
1 check passed
@tastybento tastybento deleted the copilot/fix-aoneblock-reload-error branch April 26, 2026 19:43
@sonarqubecloud
Copy link
Copy Markdown

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.

AOneBlock error on reload

2 participants