Skip to content

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

Open
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-npe-in-stats-app-state-again
Open

Fix NPE in StatsAppState.setEnabled when called before initialization#2660
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-npe-in-stats-app-state-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 28, 2026

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 <4943530+riccardobl@users.noreply.github.com>
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
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