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

UnsupportedOperationException on setting villager memory to null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • CraftBukkit version git-Spigot-df0eb25-8003ced (MC: 1.14.2) (Implementing API version 1.14.2-R0.1-SNAPSHOT)
    • Yes

      Attempting to set one of a villager's memories to null using LivingEntity#setMemory throws the following UnsupportedOperationException:

      Caused by: java.lang.UnsupportedOperationException: Do not know how to map null
              at org.bukkit.craftbukkit.v1_14_R1.entity.memory.CraftMemoryMapper.toNms(CraftMemoryMapper.java:29) ~[spigot.jar:git-Spigot-df0eb25-8003ced]
              at org.bukkit.craftbukkit.v1_14_R1.entity.CraftLivingEntity.setMemory(CraftLivingEntity.java:596) ~[spigot.jar:git-Spigot-df0eb25-8003ced]

      See attached txt file for full error when using TestPlugin.jar.

      This is despite the second argument of LivingEntity#setMemory being annotated as Nullable. Something else to note is that egg-spawned or summoned villagers have all memories null by default, so it should definitely be possible to do this.

      Reproducing:

      1. Install attached TestPlugin.jar on a 1.14.2 spigot server.
      2. Create a world and spawn a villager using a spawn egg or /summon command.
      3. Right click the villager, and the error should appear in the console.

      Test plugin source code:

      public class TestPlugin extends JavaPlugin implements Listener {
      
          @Override
          public void onEnable() {
              Bukkit.getPluginManager().registerEvents(this, this);
          }
      
          @EventHandler
          public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
              if(event.getRightClicked() instanceof Villager) {
                  ((Villager) event.getRightClicked()).setMemory(MemoryKey.HOME, null);
              }
          }
      }
      

      The same error occurs when MemoryKey.HOME is replaced with MemoryKey.JOB_SITE or MemoryKey.MEETING_POINT.

        1. TestPlugin_full_error.txt
          3 kB
          froobynooby

            Unassigned Unassigned
            froobynooby froobynooby
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: