[Bug] MC-89146 fix: NPE in LevelChunk.clearAllBlockEntities when a block entity removal re-enters the linked map

Ouverte
#573 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

@0x969 y travaille déjà.

Depuis le 1/12/2026.

  • #577 par @0x969 — ouverte

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
58/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
java
Domaine
backend

Piste de recherche

Start by locating the MC-89146 patch and its change to LevelChunk.clearAllBlockEntities; the crash trace identifies the failing loop at LevelChunk.java:697. Check how block entity removal can mutate the linked map during iteration, then reproduce the reported chunk reload sequence and verify all block entities are removed without a crash. The issue suggests iterating over a snapshot as one possible fix.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Debugify 26.3.0.0 is still the newest 26.3 release (re-checked 19 Nov 2026 against the newest 26.3 release on Modrinth).

Bug Description

Crash (client, on chunk reload near a jukebox):

java.lang.NullPointerException: Packet handling error
	at it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap$1.forEach(Object2ObjectLinkedOpenHashMap.java:1699)
	at net.minecraft.world.level.chunk.LevelChunk.clearAllBlockEntities(LevelChunk.java:697)
	at net.minecraft.world.level.chunk.LevelChunk.replaceWithPacketData(LevelChunk.java:539)
	at net.minecraft.client.multiplayer.ClientChunkCache.replaceWithPacketData(ClientChunkCache.java:118)
	at net.minecraft.client.multiplayer.ClientPacketListener.handleLevelChunkWithLight(ClientPacketListener.java:905)

The client is disconnected with "Packet handling error".

What happens

  1. MC-89146 replaces ChunkAccess.blockEntities with an Object2ObjectLinkedOpenHashMap.
  2. On level_chunk_with_light, clearAllBlockEntities runs blockEntities.values().forEach(BlockEntity::setRemoved).
  3. JukeboxBlockEntity.setRemoved fires level event 1011; the client handler calls notifyNearbyEntities. Cooking for Blockheads hooks that method and calls level.getBlockEntity on 343 nearby positions. Vanilla LevelChunk.getBlockEntity(..., CHECK) removes entries whose isRemoved() is already true, so the map is modified during the forEach.
  4. Fastutil's linked-map forEach caches the next slot index before calling the consumer. After the reentrant removal shifts the next entry (here a decorated pot) back one slot, the cached slot is empty and null is passed to setRemoved -> NPE. No null value is ever stored (containsValue(null) is false before and after).

We reproduced this offline with the real chunk data (8 block entities: spawner, chests, brushable blocks, jukebox, decorated pot) and the real jukebox / Cooking for Blockheads / fastutil code: NPE with the linked map; with vanilla's Object2ObjectOpenHashMap the same sequence completes all 8 removals. Turning off "MC-89146" in config/debugify.json avoids it, but loses that fix.

Suggested fix: keep the linked map but make the clear loop tolerate reentrant removal, e.g. iterate over a snapshot when the map is the linked one:

new ArrayList<>(this.blockEntities.values()).forEach(BlockEntity::setRemoved);

(or redirect clearAllBlockEntities to do that). Cooking for Blockheads' lookup during removal is the trigger, but any mod that calls getBlockEntity from a setRemoved side effect can hit this.

Other mods involved: Cooking for Blockheads 26.3.0.2, Lootr 1.25.42.124 (its block entities were in the chunk; incidental). Multiplayer, Fabric 26.3 pack with ~430 mods.

Version

Debugify 26.3.0.0 (Minecraft 26.3), MC-89146 enabled (default)

Fabric/Quilt Loader Version

Fabric Loader 0.20.1, Fabric API 0.165.2+26.3

Checklist
  • This bug has not been reported already (searched MC-89146, clearAllBlockEntities, "Packet handling error").
  • I am on the most up to date version (26.3.0.0 is the newest 26.3 build).
Langage dominant
Java
Étoiles
215
Forks
51
Merge moyen
1 h 42 min
PR mergées (30 j)
1

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de isXander/Debugify

Toutes les issues de isXander/Debugify

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.