PlayerInventory#setContents doesn't accept output of PlayerInventory#getContents

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • Environment:
    • This server is running CraftBukkit version 4514-Spigot-d5ca3f8-a720008 (MC: 1.21.6) (Implementing API version 1.21.6-R0.1-SNAPSHOT)
    • Yes

      When running the following code, the code should essentially act as a no-op:

      PlayerInventory playerInventory = ...;
      
      playerInventory.setContents(playerInventory.getContents()); 

      However, this currently results in the following exception:

      org.bukkit.command.CommandException: Unhandled exception executing command 'test' in plugin Test v0.0.0
          at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot-api-1.21.6-R0.1-SNAPSHOT.jar:?]
          at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:150) ~[spigot-api-1.21.6-R0.1-SNAPSHOT.jar:?]
          at org.bukkit.craftbukkit.v1_21_R5.CraftServer.dispatchCommand(CraftServer.java:925) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at org.bukkit.craftbukkit.v1_21_R5.command.BukkitCommandWrapper.run(BukkitCommandWrapper.java:50) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73) ~[brigadier-1.3.10.jar:?]
          at net.minecraft.commands.execution.tasks.ExecuteCommand.a(SourceFile:29) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(SourceFile:13) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.commands.execution.UnboundEntryAction.a(SourceFile:8) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.commands.execution.CommandQueueEntry.a(SourceFile:8) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.commands.execution.ExecutionContext.a(SourceFile:107) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.commands.CommandDispatcher.a(CommandDispatcher.java:464) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.commands.CommandDispatcher.performCommand(CommandDispatcher.java:386) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.commands.CommandDispatcher.a(CommandDispatcher.java:373) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.server.network.PlayerConnection.b(PlayerConnection.java:2055) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.server.network.PlayerConnection.lambda$handleChatCommand$8(PlayerConnection.java:2031) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.server.TickTask.run(SourceFile:18) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.util.thread.IAsyncTaskHandler.d(SourceFile:164) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.d(SourceFile:23) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1292) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:208) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.util.thread.IAsyncTaskHandler.B(SourceFile:138) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.server.MinecraftServer.bv(MinecraftServer.java:1275) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.server.MinecraftServer.B(MinecraftServer.java:1268) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.util.thread.IAsyncTaskHandler.bA(SourceFile:123) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.server.MinecraftServer.w_(MinecraftServer.java:1231) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.server.MinecraftServer.y(MinecraftServer.java:1078) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:327) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at java.base/java.lang.Thread.run(Thread.java:1583) [?:?]
      Caused by: java.lang.IllegalArgumentException: Invalid inventory size (43); expected 41 or less
          at com.google.common.base.Preconditions.checkArgument(Preconditions.java:302) ~[guava-33.3.1-jre.jar:?]
          at org.bukkit.craftbukkit.v1_21_R5.inventory.CraftInventory.setContents(CraftInventory.java:89) ~[spigot-1.21.6-R0.1-SNAPSHOT.jar:4514-Spigot-d5ca3f8-a720008]
          at com.gmail.stefvanschiedev.buildinggame.Scratch.onCommand(Scratch.java:25) ~[?:?]
          at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-api-1.21.6-R0.1-SNAPSHOT.jar:?]
          ... 27 more

      This only affects Spigot 1.21.6 and does not affect Spigot 1.21.5.

      This can be reproduced as follows:

      1. Add the attached plugin to the server.
      2. Join the server.
      3. Run the command /test.

      The full source code is also attached below.

      This seems to stem from a regression while fixing issue 8070. The getContents method returns 43 items, whereas the setContents method checks the size of the inventory, which is now only 41 items.

        1. Scratch.java
          0.7 kB
        2. test.jar
          2 kB

            Assignee:
            Unassigned
            Reporter:
            Stef van Schie
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: