java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because "this.effects" is null at org.bukkit.craftbukkit.v1_21_R1.inventory.CraftMetaFirework.applyToItem(CraftMetaFirework.java:188) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack.setItemMeta(CraftItemStack.java:325) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack.setItemMeta(CraftItemStack.java:304) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack.<init>(CraftItemStack.java:104) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack.<init>(CraftItemStack.java:97) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack.asCraftCopy(CraftItemStack.java:76) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory.firstPartial(CraftInventory.java:273) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory.addItem(CraftInventory.java:302) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at de.blablubbabc.test.inventory.firework.FireworkNoEffects.onCommand(FireworkNoEffects.java:31) ~[?:?] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-api-1.21-R0.1-SNAPSHOT.jar:?] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:150) ~[spigot-api-1.21-R0.1-SNAPSHOT.jar:?] at org.bukkit.craftbukkit.v1_21_R1.CraftServer.dispatchCommand(CraftServer.java:913) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at org.bukkit.craftbukkit.v1_21_R1.command.BukkitCommandWrapper.run(BukkitCommandWrapper.java:50) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73) ~[brigadier-1.2.9.jar:?] at net.minecraft.commands.execution.tasks.ExecuteCommand.a(SourceFile:29) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(SourceFile:13) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.commands.execution.UnboundEntryAction.a(SourceFile:8) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.commands.execution.CommandQueueEntry.a(SourceFile:8) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.commands.execution.ExecutionContext.a(SourceFile:107) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.commands.CommandDispatcher.a(CommandDispatcher.java:414) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.commands.CommandDispatcher.performCommand(CommandDispatcher.java:336) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.commands.CommandDispatcher.a(CommandDispatcher.java:323) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.server.network.PlayerConnection.b(PlayerConnection.java:1842) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.server.network.PlayerConnection.lambda$handleChatCommand$7(PlayerConnection.java:1818) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.server.TickTask.run(SourceFile:18) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.util.thread.IAsyncTaskHandler.d(SourceFile:162) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.d(SourceFile:23) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1270) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:203) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.util.thread.IAsyncTaskHandler.B(SourceFile:136) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.server.MinecraftServer.bv(MinecraftServer.java:1249) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.server.MinecraftServer.B(MinecraftServer.java:1242) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.util.thread.IAsyncTaskHandler.b(SourceFile:145) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1207) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.server.MinecraftServer.v_(MinecraftServer.java:1214) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.server.MinecraftServer.y(MinecraftServer.java:1078) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:318) ~[spigot-1.21-R0.1-SNAPSHOT.jar:dev-Spigot-146439e-3f8e416] at java.base/java.lang.Thread.run(Thread.java:1583) [?:?]
CraftMetaFirework effects can be null. A check is missing in applyToItem.
Can for example be reproduced with this plugin code:
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { try { Player player = (Player) sender; ItemStack item = new ItemStack(Material.FIREWORK_ROCKET); FireworkMeta meta = (FireworkMeta)item.getItemMeta(); meta.setPower(3); item.setItemMeta(meta); player.getInventory().addItem(item); player.sendMessage("Item given"); } catch (Exception e) { sender.sendMessage("Command execution failed: " + e.getMessage()); Test.INSTANCE.getLogger().log(Level.SEVERE, "Command execution failed!", e); } return true; }