-
Bug
-
Resolution: Fixed
-
Minor
-
None
-
None
-
Java 8u102 on Windows 10 1607
The following steps will produce a `NullPointerException` on the latest CraftBukkit/Spigot versions:
- Place a hanging entity on a block such that no blocks surround it bar the one it's attached to.
- Attempt to remove it via `Entity#remove`.
- Within the same tick, attempt to spawn a new hanging entity in the same location.
The last step will fail with a `NullPointerException`, because the server cannot find a suitable direction for the new entity since it believes the space is occupied by an entity currently marked for removal. Therefore local variable `face` will be `null` and [this line](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/CraftWorld.java?at=43ab266#1088) will fail.
The obvious solution is to modify [this line](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/CraftWorld.java?at=43ab266#1072) to include the condition `!e.isDead()`. However, I am not knowledgeable enough to say whether this would present a technical conflict, so alternatively I propose that in the case that a suitable `BlockFace` cannot be determined, an `IllegalArgumentException` is thrown to signify that and why it is not possible to spawn an entity with the given parameters, which would be much better UX than a relatively mysterious NPE.