-
Bug
-
Resolution: Fixed
-
1.19.3
-
None
-
Plausible
-
Crash
-
Very Important
-
Platform
ItemStacks have a an emptyCacheFlag that is used to return AIR instead of null from getItem(). This flag is updated every time count is set, however, and it is set to false momentarily before being updated to the true state in ItemStack.updateEmptyCacheFlag(). It is possible that calling ItemStack.setCount() on ItemStack.EMPTY on one thread during a very unlucky window can cause another thread to get null back from ItemStack.getItem(), which will almost universally cause a crash, as the method is not nullable, and returns AIR instead of null when the emptyCacheFlag is set correctly. Crashes like these are somewhat rare, but common enough that I've seen it happen close to a dozen times.
I don't have any unmodded crash reports because I always play with mods, however, this crash is easily possible in vanilla, and provides a very rare and hard to diagnose crash when calling ItemStack.setCount(), which is normally completely safe even on ItemStack.EMPTY. Ideally, this method should be changed to be atomic, and not have ItemStack.EMPTY flicker to be cached as non-empty frequently.
Crashlog from another user: https://mclo.gs/sGocG0Z
- relates to
-
MC-259574 Crash trading with a custom villager: java.lang.NullPointerException: Cannot invoke "cdp.S_()" because the return value of "cdt.c()" is null
- Resolved