[SPIGOT-6464] Getting color from undyed shulkerbox results in NPE instead of returning null Created: 22/May/21 Updated: 22/May/21 Resolved: 22/May/21 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | Prof Bloodstone | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 1 |
Labels: | None |
Version: | 3082-Spigot-9fb885e-d49530f |
Guidelines Read: | Yes |
Description |
Colorable#getColor() retuns a @Nullable DyeColor: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/material/Colorable.html#getColor() 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 |