Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Incorrect nullablility at PlayerMoveEvent.getTo()

Open Brokkonaut opened this issue 2 years ago • 3 comments

Expected behavior

PlayerMoveEvent has subclasses like PlayerTeleportEvent and PlayerPortalEvent where getTo() can return null, so PlayerMoveEvent.getTo() must be nullable.

https://github.com/PaperMC/Paper/blob/master/patches/api/0176-Fix-Spigot-annotation-mistakes.patch#L473

Observed/Actual behavior

is not

Steps/models to reproduce

Create a handler for a PlayerPortalEvent, check if getTo() returns null and get a warning

Plugin and Datapack List

no

Paper version

yes

Other

No response

Brokkonaut avatar Feb 02 '23 22:02 Brokkonaut

last I recall we looked into this, to should NEVER be null, and literally just looked like a broken side-effect of a borked patch?

electronicboy avatar Feb 03 '23 20:02 electronicboy

I am not sure, but I got some reports about NPEs in the past in one of my plugins when it did no null check there. At least other plugins could create some PlayerTeleportEvent with a null target, because in the constructor it is marked as nullable (why ever they should do that).

Brokkonaut avatar Feb 04 '23 02:02 Brokkonaut

So PlayerPortalEvent#getTo isn't null ever from server use. The constructor param is marked as nullable, but event constructor's aren't API, so that doesn't really matter. PlayerTeleportEvent#getTo does return null sometime. Is a solution to just override getTo in PlayerTeleportEvent and mark it as Nullable? Cause PlayerMoveEvent#getTo isn't nullable when its just a PlayerMoveEvent. In some sense, its not correct to think of these in a hierarchy since they all have separate HandlerList, meaning they can't be listened to by the same listener.

Machine-Maker avatar Mar 20 '23 05:03 Machine-Maker