Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-2644

Removing hanging entity and respawning new one in same location within same tick causes NPE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • Java 8u102 on Windows 10 1607

      The following steps will produce a `NullPointerException` on the latest CraftBukkit/Spigot versions:

      1. Place a hanging entity on a block such that no blocks surround it bar the one it's attached to.
      2. Attempt to remove it via `Entity#remove`.
      3. 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.

            Unassigned Unassigned
            mproncace Maxim Roncace
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: