-
Notifications
You must be signed in to change notification settings - Fork 249
Description
Bug Report: NullPointerException in PlayerDeathEvent Handling
Plugin Name: BedWars1058
Plugin Version: v25.3-SNAPSHOT
Server Software: Paper 1.21.1-133 (Mojang API)
Java Version: Java 17 (Thread.run line shows java.base/java.lang.Thread)
Full Error Log:
[18:34:08 ERROR]: Could not pass event PlayerDeathEvent to BedWars1058 v25.3-SNAPSHOT
java.lang.NullPointerException: Cannot invoke "String.trim()" because the return value of "com.andrei1058.bedwars.api.server.VersionSupport.getShopUpgradeIdentifier(org.bukkit.inventory.ItemStack)" is null
at com.andrei1058.bedwars.listeners.dropshandler.PlayerDrops.handlePlayerDrops(PlayerDrops.java:97)
... (full stack trace omitted for brevity) ...
🐞 Bug Description
When a player dies during a BedWars game, the plugin throws a NullPointerException during PlayerDeathEvent processing. This occurs specifically when attempting to call .trim() on the return value of VersionSupport.getShopUpgradeIdentifier() which is null for certain items.
🔄 Steps to Reproduce
- Start a BedWars match on Paper 1.21.1 server
- Have a player acquire an item not properly registered as a shop upgrade (e.g., custom items from other plugins or misconfigured BedWars items)
- Kill the player while they hold the invalid item
- Server throws the NullPointerException and cancels event handling
⚠ Observed Behavior
• Server log shows stack trace pointing to PlayerDrops.java:97
• Player death item drops may not process correctly
• No crash occurs, but event propagation stops
✅ Expected Behavior
- Plugin should safely handle null values returned by getShopUpgradeIdentifier()
- Event processing should complete without exceptions
- Invalid items should be handled gracefully (e.g., dropped normally or ignored)
🔍 Root Cause Analysis
The NPE occurs because:
String id = versionSupport.getShopUpgradeIdentifier(itemStack);
if (id.trim().isEmpty()) { // Throws NPE when id is null
Missing null check before calling .trim(). This fails when:
• An item exists in player's inventory that wasn't properly configured in shop upgrades
• Other plugins add custom items without BedWars identifiers
💡 Suggested Fix
// Current vulnerable code (PlayerDrops.java:97):
String id = versionSupport.getShopUpgradeIdentifier(itemStack);
if (id.trim().isEmpty()) {...}
// Proposed fix:
String id = versionSupport.getShopUpgradeIdentifier(itemStack);
if (id == null || id.trim().isEmpty()) {...} // Add null safety
ℹ Additional Context
• Reproduced on both survival and creative game modes
• Occurs consistently when players hold unregistered custom items
• Server version details from log: paper-1.21.1.jar:1.21.1-133-3cb8529
Thank you for maintaining this plugin! Let me know if you need more debugging data.