fix: handle missing phase in processPhase without NPE (Sonar S2259) - #564
Merged
Merged
Conversation
Sonar (S2259) flagged a guaranteed NullPointerException in processPhase: OneBlocksManager.getPhase() is @nullable, and the phase returned by handleGoto() was dereferenced without a check. A goto pointing below the first phase, or phase files failing to load, would crash the block-break handler and could leave the island without its magic block. processPhase now resolves the goto first and checks the resulting phase once. When no phase covers the block number it logs an error naming the island and block number, cancels the event so the block stays in place, and returns null; process() returns early on a null result. handlePhaseChange had the same latent requireNonNull and now uses a plain null check that the following line already expected. Adds two BlockListenerTest cases covering no-phase and goto-to-no-phase. Bumps version to 1.27.2. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0161Uw7dZoSjSbSH6T8hMsUQ
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Fixes the one open Sonar reliability issue (rule S2259, "Fix this access that will throw a NullPointerException") in
BlockListener.processPhase.OneBlocksManager.getPhase()is@Nullable, and the phase returned byhandleGoto()was dereferenced unchecked. A goto pointing below the first phase, or phase files failing to load, would throw inside the block-break handler.processPhasenow resolves the goto first, then checks the phase once. If no phase covers the block number it logs an error with the island and block number, cancels the event so the magic block is not lost, and returns null.process()returns early on null.handlePhaseChangehad the same latentObjects.requireNonNulland now uses a plain null check.Test plan
BlockListenerTestcases: no phase for block number, and goto target with no phase. Both assert the event is cancelled and an error is logged.BlockListenerTest(7) andBlockListenerTest2(48) pass locally.🤖 Generated with Claude Code
https://claude.ai/code/session_0161Uw7dZoSjSbSH6T8hMsUQ