Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-5860

Setting an item's itemstack to null throws error


    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • Windows 7 Professional
      OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14+36, mixed mode, sharing)

    • This server is running CraftBukkit version git-Spigot-6f4ff1b-983305b (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT)
    • Yes

      The API for Item (the entity) has a setItemStack(ItemStack) method to change the item stack this item reflects. The parameter of this method is currently set to Nullable, indicating that this method accepts null values. However, when attempting to pass in such a null value, an error occurs. This error can be viewed here: https://paste.gg/p/anonymous/e4193bdaf94f4da786feb0b2cc58ff8e.
      The underlying NMS implementation for the changes that occur when invoking this method deny the parameter to be null and throw an error if it is, not aligning with the annotation set in the API. Because of this, this error is thrown.
      It is understandable that a null parameter would not be allowed: what would a dropped item that is "null" even represent? However, in that case the annotation should be changed to NotNull to accurately reflect this.
      Attached below is a reproduction plugin that shows this behavior. The code used in this plugin to reproduce this error can be viewed here: https://paste.gg/p/anonymous/3951fecce6e64fb6845ddaf19d6bb198.

      Reproduction steps:

      1. Stop the server if it's currently enabled by executing the stop command (either from the console or as a player with operator level 4 or higher).
      2. Put the reproduction plugin that is attached below on the server by placing the file in the dedicated plugins folder.
      3. Start the server.
      4. Drop an item on the ground (by breaking a block; dropping items from the player inventory; using the summon command; etc.).
      5. Walk into this dropped item in such a way that this item is picked up. An error message should become visible in the console.

      This bug affects Spigot 1.16.1 (git-Spigot-6f4ff1b-983305b (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT)); Spigot 1.15.2 (git-Spigot-a99063f-be6aaf0 (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)); CraftBukkit 1.16.1 (git-Bukkit-983305b (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT)); and CraftBukkit 1.15.2 (git-Bukkit-be6aaf0 (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)).

            Unassigned Unassigned
            stefvanschie Stef van Schie
            0 Vote for this issue
            1 Start watching this issue