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

Calling get BlockStateMeta#getBlockState causes NPE with shield with banner

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • openjdk 14 2020-03-17
      OpenJDK Runtime Environment AdoptOpenJDK (build 14+36)
      OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14+36, mixed mode, sharing)

    • git-Spigot-ccb012a-e58a088
    • Yes

      When calling BlockStateMeta#getBlockState on a shield that has a banner pattern applied to it it causes a NullPointerException. E.g. this stacktrace 1.5.7 of my ShowItem plugin, with enabled ShowCodeDetailsInExceptionMessages of Java 14:

      [01:33:10] [Server thread/INFO]: Phoenix616 issued server command: /show
      [01:33:10] [Server thread/ERROR]: null
      org.bukkit.command.CommandException: Unhandled exception executing command 'show' in plugin ShowItem v1.5.7 (compiled at 2020-07-05T00:19:32Z)
      	at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at org.bukkit.craftbukkit.v1_16_R1.CraftServer.dispatchCommand(CraftServer.java:757) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.PlayerConnection.handleCommand(PlayerConnection.java:1703) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.PlayerConnection.a(PlayerConnection.java:1546) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.TickTask.run(SourceFile:18) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.IAsyncTaskHandler.executeTask(SourceFile:144) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.IAsyncTaskHandler.executeNext(SourceFile:118) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.MinecraftServer.aZ(MinecraftServer.java:943) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.MinecraftServer.executeNext(MinecraftServer.java:936) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.MinecraftServer.sleepForTick(MinecraftServer.java:920) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.MinecraftServer.v(MinecraftServer.java:852) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at net.minecraft.server.v1_16_R1.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at java.lang.Thread.run(Thread.java:832) [?:?]
      Caused by: java.lang.NullPointerException: Cannot invoke "net.minecraft.server.v1_16_R1.Block.getBlockData()" because the return value of "org.bukkit.craftbukkit.v1_16_R1.util.CraftMagicNumbers.getBlock(org.bukkit.Material)" is null
      	at org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMetaBlockState.getBlockState(CraftMetaBlockState.java:301) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	at de.themoep.utils.ItemMatcher$MatchDefinition.matches(ItemMatcher.java:188) ~[?:?]
      	at de.themoep.utils.ItemMatcher.getMatching(ItemMatcher.java:63) ~[?:?]
      	at de.themoep.ShowItem.ShowItemCommand.onCommand(ShowItemCommand.java:169) ~[?:?]
      	at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot.jar:git-Spigot-ccb012a-e58a088]
      	... 18 more

      This happens no matter if hasBlockState was checked before or not. (But that shouldn't matter anyways, getBlockState should return a fresh one if the meta doesn't have a state.

      As far as I can tell this happens because CraftMagicNumbers#getBlock tries to use the material of the item to get a block which a shield obviously isn't. It seem like there is more special-casing necessary for shields than what is already in place.

            Unassigned Unassigned
            Phoenix616 Phoenix616
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: