1. Guest, as per the stickied thread, this forum has not been in use since 2014. All bugs and feature requests should be posted to JIRA.

Rejected Weird error with toString() in EntityType enum.

Discussion in 'Bugs & Feature Requests' started by funkiben, Jul 14, 2013.

  1. No idea what is causing this, but when I try using .toString() with a EntityType enum that has a underscore in its name I get a NullPointerException.

    The error:
    Code (Text):
    19:16:39 [SEVERE] Error occurred while enabling MobArena v1.0 (Is it up to date?)
    java.lang.NullPointerException
    at com.funkiserver.mobarena.Game.setAllowedMobs(Game.java:169)
    at com.funkiserver.mobarena.MobArena.reloadGamesFromConfig(MobArena.java:209)
    at com.funkiserver.mobarena.MobArena.onEnable(MobArena.java:62)
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:382)
    at org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugin(CraftServer.java:286)
    at org.bukkit.craftbukkit.v1_6_R2.CraftServer.enablePlugins(CraftServer.java:268)
    at net.minecraft.server.v1_6_R2.MinecraftServer.l(MinecraftServer.java:319)
    at net.minecraft.server.v1_6_R2.MinecraftServer.f(MinecraftServer.java:296)
    at net.minecraft.server.v1_6_R2.MinecraftServer.a(MinecraftServer.java:256)
    at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.java:164)
    at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:397)
    at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
     
    My code:
    Code (Text):
    public void setAllowedMobs(List<EntityType> mobs) {
        allowedMobs = mobs;
        List<String> names = new ArrayList<String>();
        for (EntityType mob : allowedMobs) {
            names.add(mob.toString()); //line 169
        }
        plugin.getConfig().set("arenas." + name + ".allowed_mobs",names);
    }
     
  2. md_5

    Administrator Developer

    You do realise a list can have null elements? In this case mob is null because an element of allowedMobs is null. There is no error here in Spigot code.
     
  3. I'm using EntityType.fromName() to convert strings from the config to EntityType's, and I think this is whats causing the null elements. It was was working with everything until I tried CAVE_SPIDER and PIG_ZOMBIE. I made this instead and it works:

    Code (Text):
    public EntityType getEntityTypeFromName(String name) {
        for (EntityType entityType : EntityType.values()) {
            if (entityType.toString().equals(name)) {
                return entityType;
            }
        }
        return null;
    }
     
    #3 funkiben, Jul 14, 2013
    Last edited: Jul 14, 2013