Getting color from undyed shulkerbox results in NPE instead of returning null

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None
    • 3082-Spigot-9fb885e-d49530f
    • Yes

      Colorable#getColor() retuns a @Nullable DyeColor: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/material/Colorable.html#getColor()
      As per description:
      This may be null to represent the default color of an object, if the object has a special default color (e.g Shulkers).

      If you look at the ShulkerBox interface though, you'll notice that getColor() is marked as @NotNull DyeColor: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/block/ShulkerBox.java

      If you look into Spigot-Server/src/main/java/org/bukkit/craftbukkit/block/CraftShulkerBox.java, you'll notice:

      return DyeColor.getByWoolData((byte) ((BlockShulkerBox) block).color.getColorIndex());
      

      This is the cause of NPE, since block.color will be null in case of shulkerboxes without color.

      This can easily be replicate with grakkit by standing on a regular shulkerbox and running:

      /js self.getWorld().getBlockAt(self.getLocation().add(0, -1, 0)).getState().getColor()
      

      If you use a modern java like Java16, you'll see:

      java.lang.NullPointerException: Cannot invoke "net.minecraft.server.v1_16_R3.EnumColor.getColorIndex()" because "block.color" is null
      

            Assignee:
            Unassigned
            Reporter:
            Prof Bloodstone
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: