Skip to content

Fix NPE in StatsAppState.setEnabled when called before initialization - #2660

Merged
riccardobl merged 2 commits into
masterfrom
copilot/fix-npe-in-stats-app-state-again
Apr 2, 2026
Merged

Fix NPE in StatsAppState.setEnabled when called before initialization#2660
riccardobl merged 2 commits into
masterfrom
copilot/fix-npe-in-stats-app-state-again

Conversation

Copilot AI commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

StatsAppState.setEnabled() throws a NullPointerException when called before initialize() (e.g. from simpleInitApp), because fpsText, darkenFps, statsView, and darkenStats are not yet created.

Changes

  • setEnabled(): Added an early-return null guard on fpsText. super.setEnabled() is still called to persist the flag; the UI update is deferred until components exist.
  • initialize(): Calls setEnabled(isEnabled()) after loading all UI components, so any enabled state set pre-initialization is applied correctly.
// Previously threw NPE:
stateManager.getState(StatsAppState.class).setEnabled(false); // called in simpleInitApp

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

When setEnabled() is called before initialize() (e.g. in simpleInitApp),
fpsText/darkenFps/statsView/darkenStats are null, causing an NPE.

Fix: add a null guard at the start of setEnabled() that returns early if
the UI components haven't been created yet. The enabled flag is still
saved via super.setEnabled(). Then, at the end of initialize(), call
setEnabled(isEnabled()) to apply any pre-initialization enabled state
to the freshly created components.

Agent-Logs-Url: https://github.com/jMonkeyEngine/jmonkeyengine/sessions/4fd1f71f-451e-4425-8e83-ae69d6b1ce0a

Co-authored-by: riccardobl <[email protected]>
Copilot AI changed the title [WIP] Fix NPE in StatsAppState.setEnabled during app init Fix NPE in StatsAppState.setEnabled when called before initialization Mar 28, 2026
Copilot AI requested a review from riccardobl March 28, 2026 09:39
@riccardobl
riccardobl marked this pull request as ready for review March 28, 2026 09:42
@yaRnMcDonuts yaRnMcDonuts added this to the v3.10.0 milestone Mar 28, 2026
@riccardobl
riccardobl merged commit faab398 into master Apr 2, 2026
17 checks passed
@riccardobl
riccardobl deleted the copilot/fix-npe-in-stats-app-state-again branch May 28, 2026 21:54
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.

StatsAppState.setEnabled fires NPE if called in app init

3 participants