review: remove null CoreRegistry, guard null binds/providers, fix Mermaid#5320
review: remove null CoreRegistry, guard null binds/providers, fix Mermaid#5320agent-refr wants to merge 7 commits intoMovingBlocks:developfrom
Conversation
📝 WalkthroughWalkthroughDeferred CoreRegistry context initialization from the constructor to Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
docs/EngineStartUp/Engine-States.mdengine/src/main/java/org/terasology/engine/core/TerasologyEngine.javaengine/src/main/java/org/terasology/engine/core/subsystem/config/BindsSubsystem.javaengine/src/main/java/org/terasology/engine/persistence/internal/ReadWriteStorageManager.java
engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java
Outdated
Show resolved
Hide resolved
engine/src/main/java/org/terasology/engine/persistence/internal/ReadWriteStorageManager.java
Outdated
Show resolved
Hide resolved
…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>
afe24b8 to
935710c
Compare
…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>
There was a problem hiding this comment.
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
TerasologyEngineconstructor behavior aroundCoreRegistrycontext 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.
engine/src/main/java/org/terasology/engine/persistence/internal/ReadWriteStorageManager.java
Outdated
Show resolved
Hide resolved
engine/src/main/java/org/terasology/engine/persistence/internal/ReadWriteStorageManager.java
Outdated
Show resolved
Hide resolved
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>
Summary
Fifth review follow-up to #5299 (gestalt-di migration). One critical fix, three defensive guards, one doc fix.
Changes
Test Plan
🤖 Generated with Claude Code