Skip to content

review: remove null CoreRegistry, guard null binds/providers, fix Mermaid#5320

Open
agent-refr wants to merge 7 commits intoMovingBlocks:developfrom
SiliconSaga:review/post-di-phase4
Open

review: remove null CoreRegistry, guard null binds/providers, fix Mermaid#5320
agent-refr wants to merge 7 commits intoMovingBlocks:developfrom
SiliconSaga:review/post-di-phase4

Conversation

@agent-refr
Copy link
Copy Markdown
Collaborator

@agent-refr agent-refr commented Apr 3, 2026

AI-assisted PR. Filed by agent driven by @Cervator via GDD.

Summary

Fifth review follow-up to #5299 (gestalt-di migration). One critical fix, three defensive guards, one doc fix.

Changes

  • TerasologyEngine constructor: Remove premature CoreRegistry.setContext() call that passed null rootContext. The correct call happens in initialize() after rootContext is created.
  • BindsSubsystem: Null-check mouseWheelUpBind/mouseWheelDownBind before accessing getId() — they can be null after clearBinds().
  • ReadWriteStorageManager: Guard ChunkProvider and NetworkSystem provider access in createSaveTransaction() with separate null checks and specific error messages.
  • Engine-States.md: Fix Mermaid subgraph ID collision — LoadingStepUpdate was used as both node and subgraph ID.

Test Plan

  • Engine compilation passes
  • Single-player game starts

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

📝 Walkthrough

Walkthrough

Deferred CoreRegistry context initialization from the constructor to initialize(); added null guards for mouse wheel binds and for resolved ChunkProvider/NetworkSystem with explicit errors; and relinked a Mermaid edge to target a labeled subgraph node in documentation.

Changes

Cohort / File(s) Summary
Documentation
docs/EngineStartUp/Engine-States.md
Relinked Mermaid edge to target the labeled LoadingStepUpdate[Step Update] subgraph node.
Engine initialization
engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java
Replaced early CoreRegistry.setContext(rootContext) in constructor with CoreRegistry.setContext(null) so the context is set later in initialize().
Input binding null-safety
engine/src/main/java/org/terasology/engine/core/subsystem/config/BindsSubsystem.java
Added null checks for mouseWheelUpBind and mouseWheelDownBind before calling getId() to avoid NPEs.
Save transaction validation
engine/src/main/java/org/terasology/engine/persistence/internal/ReadWriteStorageManager.java
Eagerly resolve ChunkProvider and NetworkSystem to local instances, validate non-null with explicit IllegalStateException messages, use locals when building save transactions; isRunModeAllowSaving() now early-returns false if either is null and re-resolves instances for remaining checks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • BenjaminAmos

Poem

🐰 I hopped through lines both small and neat,
I nudged a guard so code won't meet defeat,
Held context back until its cue,
Linked the step so charts stay true,
Hop—safe builds and tasty root! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: CoreRegistry removal, null guards for binds/providers, and Mermaid diagram fix.
Description check ✅ Passed The pull request description is directly related to the changeset, providing clear summaries of all four changes (TerasologyEngine, BindsSubsystem, ReadWriteStorageManager, Engine-States.md) with appropriate context about the gestalt-di migration follow-up.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java`:
- Line 185: The constructor for TerasologyEngine must explicitly clear the
global CoreRegistry to avoid leaking a previous engine/context between
builder.build() and initialize(); update the TerasologyEngine constructor to
call the appropriate CoreRegistry reset/clear method (e.g., CoreRegistry.clear()
or equivalent) immediately on construction (before any listeners, subscriptions,
or early callbacks are registered) so the old services are not visible until
initialize() repopulates the registry.

In
`@engine/src/main/java/org/terasology/engine/persistence/internal/ReadWriteStorageManager.java`:
- Around line 270-277: The guard checks in createSaveTransaction() are bypassed
because update() calls isRunModeAllowSaving() which dereferences
networkSystem.get() and chunkProvider.get() without null checks; change
isRunModeAllowSaving() to avoid directly calling networkSystem.get() and
chunkProvider.get() (use Optional.isPresent()/Supplier#orElse(null) or retrieve
via the same null-safe pattern used in createSaveTransaction()), or have
isRunModeAllowSaving() accept the already-resolved ChunkProvider and
NetworkSystem parameters so it only examines non-null values; update references
to isRunModeAllowSaving(), update(), networkSystem, chunkProvider, and
createSaveTransaction() accordingly to ensure no unchecked .get() is performed
before null-safe guards run.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8885dd26-c626-4b14-8588-1327250b2186

📥 Commits

Reviewing files that changed from the base of the PR and between a1d4f8a and afe24b8.

📒 Files selected for processing (4)
  • docs/EngineStartUp/Engine-States.md
  • engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java
  • engine/src/main/java/org/terasology/engine/core/subsystem/config/BindsSubsystem.java
  • engine/src/main/java/org/terasology/engine/persistence/internal/ReadWriteStorageManager.java

Cervator and others added 5 commits April 2, 2026 23:07
…ctor

The constructor called CoreRegistry.setContext(rootContext) before
rootContext was created, passing null. The correct setContext call
happens in initialize() after rootContext is constructed. Removed the
premature call and updated the comment.

CodeRabbit flagged this on PR MovingBlocks#5299 (outside-diff-range, critical).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mouseWheelUpBind and mouseWheelDownBind can be null after clearBinds()
and may not be re-assigned if no wheel bindings are registered. Add
null checks before accessing getId().

CodeRabbit flagged this on PR MovingBlocks#5299 (outside-diff-range, minor).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
LoadingStepUpdate was used as both a node label and a subgraph ID,
which share the same Mermaid namespace. Move the label to the subgraph
declaration so the ID is only defined once.

CodeRabbit flagged this on PR MovingBlocks#5299 (outside-diff-range, minor).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…action

ChunkProvider and NetworkSystem providers are dereferenced unconditionally
in createSaveTransaction(). A save triggered during a state transition
could NPE if the providers are not yet resolved. Guard with null checks
and fail with a clear message.

CodeRabbit flagged this on PR MovingBlocks#5299 (outside-diff-range, major).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Split the combined null check into separate checks with specific error
messages so the failing provider is immediately identifiable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@agent-refr agent-refr force-pushed the review/post-di-phase4 branch from afe24b8 to 935710c Compare April 3, 2026 03:07
…nModeAllowSaving

- TerasologyEngine: explicitly clear CoreRegistry in constructor to
  prevent stale context leakage between build() and initialize().
- ReadWriteStorageManager: guard null providers in isRunModeAllowSaving()
  which is called before createSaveTransaction() and could NPE during
  state transitions.

CodeRabbit review feedback on PR MovingBlocks#5320.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Follow-up hardening after the gestalt-di migration to prevent null-related issues during engine bring-up, saving, and input binding enumeration, plus a Mermaid diagram fix in engine startup docs.

Changes:

  • Adjust TerasologyEngine constructor behavior around CoreRegistry context initialization/clearing.
  • Add defensive null-guards for mouse wheel binds and save-transaction dependencies (ChunkProvider, NetworkSystem).
  • Fix a Mermaid subgraph ID collision in engine startup state documentation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
engine/src/main/java/org/terasology/engine/persistence/internal/ReadWriteStorageManager.java Guard ChunkProvider/NetworkSystem access during save transaction creation; add a defensive early-return in save eligibility check.
engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java Replace a premature CoreRegistry.setContext(rootContext) (where rootContext is not yet created) with an explicit context clear.
engine/src/main/java/org/terasology/engine/core/subsystem/config/BindsSubsystem.java Prevent NPE when mouse wheel binds are unset (e.g., after clearBinds()).
docs/EngineStartUp/Engine-States.md Resolve Mermaid ID collision by separating node/subgraph labeling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Rename short variable names (chunks, network) to descriptive names
(chunkProviderInstance, networkSystemInstance) for consistency across
createSaveTransaction() and isRunModeAllowSaving(). Assign
chunkProvider.get() to a local in isRunModeAllowSaving() to avoid
redundant calls.

Copilot review feedback on PR MovingBlocks#5320.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

4 participants