Skip to content

Unsetting leash holder in EntityUnleashEvent causes NPE #13645

@datatags

Description

@datatags

Preface: why am I doing this?

To avoid the lead dropping as an item. I'm aware Paper has an API for this, but this trick is handy because it works on any platform I've encountered, on any version since the introduction of EntityUnleashEvent, even before Paper's setDropLeash method was available.

Expected behavior

The entity to be unleashed, without the lead dropping as an item.

Observed/Actual behavior

The lead correctly does not drop, but the target entity of the EntityUnleashEvent is removed from the world entirely, and the server emits this NullPointerException: https://pastebin.com/zcPZCDki

Steps/models to reproduce

Compile and run a plugin containing the following code:

public class MyPlugin extends JavaPlugin implements Listener {
    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void onLeashBreak(EntityUnleashEvent event) {
        if (event.getEntity() instanceof LivingEntity) {
            ((LivingEntity)event.getEntity()).setLeashHolder(null);
        }
    }
}

Then, join the server and attach a lead to an entity. Ensure either that the entity cannot move, or that you are very fast. Then, move away from the entity such that the lead breaks. Observe that the entity no longer exists, and the aforementioned stack trace appears in the console.

Plugin and Datapack List

> plugins
[12:42:50 INFO]: ℹ Server Plugins (1):
[12:42:50 INFO]: Bukkit Plugins:
[12:42:50 INFO]:  - Floopin-gradle

The code of which is contained above

Paper version

> ver
[12:50:37 INFO]: Checking version, please wait...
[12:50:37 INFO]: This server is running Paper version 1.21.11-117-main@79c77f5 (2026-02-20T00:03:51Z) (Implementing API version 1.21.11-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.11-91-a0f626b (MC: 1.21.11)

Other

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions