Skip to content

Fix IndexOutOfBoundsException in Family branch accessors for families without a stripped branch#1207

Open
Arilas wants to merge 1 commit into
DynamicTreesTeam:develop/26.1.2from
Arilas:fix/branch-block-bounds
Open

Fix IndexOutOfBoundsException in Family branch accessors for families without a stripped branch#1207
Arilas wants to merge 1 commit into
DynamicTreesTeam:develop/26.1.2from
Arilas:fix/branch-block-bounds

Conversation

@Arilas

@Arilas Arilas commented Jul 24, 2026

Copy link
Copy Markdown

Problem

Family.getBranchBlock(int) and Family.getBranchItem(int) index directly into the branches list. Any family that has no stripped branch entry (only BRANCH_INDEX populated) throws when getStrippedBranch() is called:

java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
  at com.dtteam.dynamictrees.tree.family.Family.getBranchBlock(Family.java)
  at com.dtteam.dynamictrees.tree.family.Family.getStrippedBranch(Family.java)
  ... (client model handling code iterating families/branch blocks)

This is easy to hit in practice: several add-on tree pack families (e.g. from dtbop / dtterralith) register families without stripped branches, and any client-side code that walks families and asks for the stripped branch (model handling does) crashes repeatedly during model bake.

Fix

Bounds-check the index in the two protected accessors and return Optional.empty(), which is what their Optional return type already promises: "no such branch". No signature changes; callers that use ifPresent/map now behave correctly for families lacking a stripped branch.

Found while running a Fabric build in a full production instance with add-on tree packs.

🤖 Generated with Claude Code

… without a stripped branch

Family.getBranchBlock(int)/getBranchItem(int) index straight into the
branches list, so any family that has no stripped branch entry (common
for add-on tree pack families) crashes consumers of getStrippedBranch()
with "Index 1 out of bounds for length 1" during client model handling.

Bounds-check the index and return Optional.empty(), honoring the
accessors' Optional contract.

Co-Authored-By: Claude Fable 5 <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.

1 participant