Skip to content

fix: handle missing phase in processPhase without NPE (Sonar S2259) - #564

Merged
tastybento merged 1 commit into
developfrom
fix/sonar-null-phase-processphase
Sep 14, 2026
Merged

tastybento merged 1 commit into
developfrom
fix/sonar-null-phase-processphase

Conversation

@tastybento

Copy link
Copy Markdown
Member

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 by handleGoto() was dereferenced unchecked. A goto pointing below the first phase, or phase files failing to load, would throw inside the block-break handler.
  • processPhase now 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.
  • handlePhaseChange had the same latent Objects.requireNonNull and now uses a plain null check.
  • Version bumped to 1.27.2.

Test plan

  • New BlockListenerTest cases: no phase for block number, and goto target with no phase. Both assert the event is cancelled and an error is logged.
  • BlockListenerTest (7) and BlockListenerTest2 (48) pass locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_0161Uw7dZoSjSbSH6T8hMsUQ

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
@sonarqubecloud

Copy link
Copy Markdown

@tastybento
tastybento merged commit ed3d9dc into develop Sep 14, 2026
3 checks passed
@tastybento
tastybento deleted the fix/sonar-null-phase-processphase branch September 14, 2026 12:14
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.

1 participant