Skip to content

Fix NPE in checkUserPlacedAllDecrees when DECREE_DATA component is null - #337

Open
possibly6 wants to merge 1 commit into
ejektaflex:devfrom
possibly6:fix/npe-checkUserPlacedAllDecrees
Open

possibly6 wants to merge 1 commit into
ejektaflex:devfrom
possibly6:fix/npe-checkUserPlacedAllDecrees

Conversation

@possibly6

Copy link
Copy Markdown

Summary

Fixes the server-freeze crash described in #336.

BoardBlockEntity.checkUserPlacedAllDecrees used a non-null assertion (!!) on the DECREE_DATA data component. When the component was absent — for example on a decree stack duplicated out-of-band (creative pick-block on a board slot, modded item manipulation, or an NBT-cleared stack from another mod) — the !! threw an NPE on the server thread, which the ServerHangWatchdog then escalated into a full server freeze several minutes later.

Fix

Replace the !! with an early return, matching the null-safe patterns already used elsewhere in this file:

  • Line 140: it[BountifulContent.DECREE_DATA]?.ids ?: emptySet()
  • Line 295: val info = stack[BountifulContent.BOUNTY_INFO] ?: continue

The count == 0 early return above already covers the consumed-stack case, so the new ?: return only triggers on the truly null-component case the !! was crashing on.

Reproduction

Per the issue:

Caused by: java.lang.NullPointerException
  at io.ejekta.bountiful.content.board.BoardBlockEntity.checkUserPlacedAllDecrees(BoardBlockEntity.kt:271)
  at io.ejekta.bountiful.content.board.BoardBlockEntity.onUserPlacedDecree(BoardBlockEntity.kt:264)
  at io.ejekta.bountiful.content.gui.BoardDecreeSlot.safeInsert(BoardDecreeSlot.kt:20)

The crash report points to line 271, which was the !! expression in the original source (and is the decreeData = … line in this PR's diff). Lines and surrounding context match the reported stack trace.

Risk

Trivial. One-line behavioural change (skip the function instead of crashing) on a code path that previously took the server down. No public API changes, no new imports.

The !! on newStack[BountifulContent.DECREE_DATA] caused a server
freeze (ServerHangWatchdog) when the data component was absent
on a decree stack — for example when a stack was duplicated
out-of-band (creative pick-block on a board slot, modded item
manipulation, or NBT-cleared stack from another mod).

Replace the unsafe non-null assertion with an early return,
matching the null-safe patterns already used elsewhere in the
file (e.g. line 140 / BOUNTY_INFO usage at line 295).

Fixes ejektaflex#336
@ejektaflex

Copy link
Copy Markdown
Owner

I'm a bit hesitant to merge this because the fix hasn't been tested, and it pulls in AI comments. I'll make the change locally and validate before releasing a new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants