Skip to content

Bug Report: NullPointerException in PlayerDeathEvent Handling #1100

@Blacklaegend

Description

@Blacklaegend

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

  1. Start a BedWars match on Paper 1.21.1 server
  2. Have a player acquire an item not properly registered as a shop upgrade (e.g., custom items from other plugins or misconfigured BedWars items)
  3. Kill the player while they hold the invalid item
  4. 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

  1. Plugin should safely handle null values returned by getShopUpgradeIdentifier()
  2. Event processing should complete without exceptions
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions