A merchant trade select packet sent from the client to the server is not checked for an index that is less than 0, only less than the size of the trade offer list. Because of this, sending a negative index such as -1
will cause an ArrayIndexOutOfBoundsException
to be thrown and logged to the console.
[12:00:00] [Server thread/FATAL] (Minecraft) Error executing task on Server
java.lang.ArrayIndexOutOfBoundsException: null
Code analysis (Yarn mappings):
public void onMerchantTradeSelect(SelectMerchantTradeC2SPacket packet) {
NetworkThreadUtils.forceMainThread(packet, this, (ServerWorld) this.player.getServerWorld());
int tradeId = packet.getTradeId();
ScreenHandler screenHandler = this.player.currentScreenHandler;
if (screenHandler instanceof MerchantScreenHandler) {
MerchantScreenHandler merchantScreenHandler = (MerchantScreenHandler) screenHandler;
// Check for i >= 0 before calling the screen handler method(s)
merchantScreenHandler.setRecipeIndex(tradeId);
merchantScreenHandler.switchTo(tradeId);
}
}
Comments 8

Please keep messages such as these in the dedicated Mojira subreddit post: https://www.reddit.com/r/Mojira/comments/iqitfw/the_minecraft_java_edition_bug_tracker_has_just/
Thanks 🙂
Any further comments that are not related to the bug will be removed - don't get me wrong, I agree with the sentiment - but we have a separated Reddit post for this which I linked above. Thanks!