NPE in CraftSign

Discussion in 'Plugin Development' started by Philipp15b, Apr 4, 2013.

Thread Status:
Not open for further replies.
  1. Hi,
    when saving data about signs at shutdown, users of my plugin report that sometimes there is a NPE in CraftSign when I'm trying to call getState() on a Block.

    Code:
    java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_5_R2.block.CraftSign.<init>(CraftSign.java:17)
            at org.bukkit.craftbukkit.v1_5_R2.block.CraftBlock.getState(CraftBlock.java:243)
    The block must be a have the material sign, or else it would not try to create a new CraftSign. Then, it seems there is no TileEntitySign at this place anymore.

    Is this a bug in Bukkit or is this my fault?

    Thanks in advance,
    Philipp
     
  2. Offline

    1SmallVille1

    well we need your code to help. What's on lines 17 and 243?
    Edit: wrong line number, thanks chase
     
  3. Offline

    chasechocolate

    *243
     
  4. You should post the full stack trace and your code where you call the getState().
     
  5. I doubt that would help as the code is pretty complicated - but here you go:

    Code:
    2013-04-04 10:59:33 [SEVERE] [MagicSigns] Error saving Magic Sign of type 'de.philworld.bukkit.magicsigns.signs.command.ConsoleCommandSign':
    java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_5_R2.block.CraftSign.<init>(CraftSign.java:17)
            at org.bukkit.craftbukkit.v1_5_R2.block.CraftBlock.getState(CraftBlock.java:243)
            at de.philworld.bukkit.magicsigns.signs.MagicSign.isMasked(MagicSign.java:155)
            at de.philworld.bukkit.magicsigns.config.MagicSignSerializationProxy.<init>(MagicSignSerializationProxy.java:41)
            at de.philworld.bukkit.magicsigns.signs.MagicSign.serialize(MagicSign.java:193)
            at de.philworld.bukkit.magicsigns.MagicSigns.saveSigns(MagicSigns.java:256)
            at de.philworld.bukkit.magicsigns.MagicSigns.onDisable(MagicSigns.java:129)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:219)
            at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:481)
            at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:400)
            at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:393)
            at org.bukkit.craftbukkit.v1_5_R2.CraftServer.disablePlugins(CraftServer.java:277)
            at net.minecraft.server.v1_5_R2.MinecraftServer.stop(MinecraftServer.java:331)
            at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:438)
            at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    The code is available on GitHub: MagicSigns. Some links: MagicSign.java:155, MagicSignSerializationProxy.java:41.

    The code is called when the server shuts down and MagicSigns (objects describing a sign with some extra functionality) are converted to MagicSignSerializationProxies to save them. To save some space, I try to check if there are different lines on the sign so that unchanged lines don't have to be saved.

    But I think the issue should not have anything to do with this, as Blocks are managed by Bukkit and the API should never throw an NPE.
     
  6. Well, you need to find out in what cases that NPE triggers to be able to trigger it manually, the problem is in the CraftBukkit code, my guess is that world.getTileEntityAt(getX(), getY(), getZ()) returns null for some reason, look into that... or if that does not return null, then it returns a TileEntitySign with null 'lines' field.

    It's a switch() so any of the 3 cases trigger the new CraftSign() code.
     
  7. Okay, I think I have found out what caused the problem, it was already reported as a bug in Leaky. The problem was that the chunk was unloaded while I was keeping a reference to the Block. This is currently not documented anywhere.
     
Thread Status:
Not open for further replies.

Share This Page