Solved NPE On Plugin Disable

Discussion in 'Plugin Development' started by Alshain01, Jan 30, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Alshain01

    Ok guys, this time I need help tracking down an NPE. I have some data that stays resident in memory while the plugin is running and I offload it using ConfigurationSerializable when the plugin stops. For some reason I get this NPE.

    Show Spoiler
    Code:
    [22:43:57] [Server thread/INFO]: [RocketTeleport] Disabling RocketTeleport v1.1.0
    [22:43:57] [Server thread/ERROR]: Error occurred while disabling RocketTeleport v1.1.0 (Is it up to date?)
    java.lang.NullPointerException
        at io.github.alshain01.RocketTeleport.LaunchPad.write(LaunchPad.java:65) ~[?:?]
        at io.github.alshain01.RocketTeleport.RocketTeleport.onDisable(RocketTeleport.java:51) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:220) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:481) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:403) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:396) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.disablePlugins(CraftServer.java:293) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.stop(MinecraftServer.java:375) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:488) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    


    So here is my onDisable()
    Code:java
    1. @Override
    2. public void onDisable() {
    3. data.getConfig().createSection("LaunchPads"); //Overwrite every time
    4. launchPad.write(data.getConfig().getConfigurationSection("LaunchPads"));
    5. data.saveConfig();
    6. ConfigurationSerialization.unregisterClass(Rocket.class);
    7. }


    Which is calling launchPad.write() that is indicated as the source of the NPE:
    Note: launchpads is populated elsewhere but the server with the NPE, it should not be empty (even if it was the iterator would be bypassed entirely). The locations that are stored are at some point taken directly from events, I don't create them myself.

    Code:java
    1. private final Map<Location, Rocket> launchpads = new ConcurrentHashMap<Location, Rocket>();
    2.  
    3. void write(ConfigurationSection config) {
    4. for(Location l : launchpads.keySet()) {
    5. // Line below is Line 65
    6. String loc = l.getWorld().getName() + "," + l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ();
    7. config.set(loc, launchpads.get(l).serialize());
    8. }
    9. }


    So, I just don't see what could be null. If there isn't enough here, the GitHub for the project has it all.

    Thanks!
    -Alshain01
     
  2. Offline

    xTrollxDudex

    Alshain01
    First off, why ConcurrentHashMap? You certainly aren't implementing thread safety anywhere in your plugin, and these should not be used asynchronously, and if you did, use Collections.synchronizedMap(...).

    I believe that your error comes from the fact that your CustomYML is assigned to your plugin before it is enabled, resulting in a null instance of org.bukkit.plugin.Plugin being passed to the CustomYML field.
    You use it to write data in the onDisable, so that is probably the issue.

    Also, package names should be lowercase.
     
  3. Offline

    Alshain01

    xTrollxDudex Well I tried moving the initializer to the onEnable and changed to a hash map and now I'm getting a strange error I'm not sure what to make of. It's looking for an <init>() method.

    Code:java
    1. [00:00:17] [Server thread/ERROR]: Could not load 'plugins\RocketTeleport.jar' in folder 'plugins'
    2. org.bukkit.plugin.InvalidPluginException: java.lang.NoSuchMethodException: io.github.alshain01.rocketteleport.RocketTeleport.<init>()
    3. at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    4. at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:308) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    5. at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:231) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    6. at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.java:255) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    7. at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:233) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    8. at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    9. at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    10. at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:126) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11. at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:424) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    12. at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    13. Caused by: java.lang.NoSuchMethodException: io.github.alshain01.rocketteleport.RocketTeleport.<init>()
    14. at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.7.0_45]
    15. at java.lang.Class.getConstructor(Unknown Source) ~[?:1.7.0_45]
    16. at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:176) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    17. ... 9 more


    Oh nevermind, somehow my class got demoted. But still getting the NPE

    xTrollxDudex Found it. I'm trying to deserialze the world name from data.yml into a world before the world is loaded. Not going to fix it tonight, but thanks, you've been a big help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page