Weird ClassCastException after reload

Discussion in 'Plugin Development' started by Delocaz, Apr 14, 2014.

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

    Delocaz

    I have made a simple plugin for "renting" out furnaces for money. Everything works completely fine until I reload, with a ClassCastException, which oddly says there was an error casting FurnaceMeta to FurnaceMeta (which makes no sense).

    Here's the code: https://gist.github.com/CrateMuncher/51d4445fd6611f93a4ba

    Here's the stack trace:
    Code:
    [21:41:44 ERROR]: Could not pass event FurnaceSmeltEvent to RentAFurnace v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:294) ~[spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:501) [spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:486) [spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at net.minecraft.server.v1_7_R3.TileEntityFurnace.burn(TileEntityFurnace
    .java:263) [spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at net.minecraft.server.v1_7_R3.TileEntityFurnace.h(TileEntityFurnace.ja
    va:177) [spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at net.minecraft.server.v1_7_R3.World.tickEntities(World.java:1255) [spi
    got.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at net.minecraft.server.v1_7_R3.WorldServer.tickEntities(WorldServer.jav
    a:481) [spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:6
    49) [spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:2
    60) [spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:5
    58) [spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java
    :469) [spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6
    28) [spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
    Caused by: java.lang.ClassCastException: net.cratemuncher.rentafurnace.FurnaceMe
    ta cannot be cast to net.cratemuncher.rentafurnace.FurnaceMeta
            at net.cratemuncher.rentafurnace.RentAFurnace.getFurnaceMetadata(RentAFu
    rnace.java:233) ~[?:?]
            at net.cratemuncher.rentafurnace.RentAFurnace.onFurnaceSmelt(RentAFurnac
    e.java:54) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
    _51]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
    _51]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_51]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:292) ~[spigot.jar:git-Bukkit-1.7.2-R0.3-21-g1ab090e-b3050jnks]
            ... 12 more
    The line numbers don't match up (since I removed a huge commented-out block of code), but line 233 is line 168.

    This ONLY happens after I /reload the server.

    I am really stumped by this, please help.
     
  2. Offline

    caseif

    I found a SO question that may give some insight as to what's going wrong. Basically, it would seem that the object you're trying to cast was loaded by the classloader from before the reload, but the class in the context in which the exception is thrown was loaded by a different one (which replaced the original after the reload). I'm not entirely sure how you can fix it, but you'll basically need to recreate the meta in the case of the plugin being reloaded.
     
  3. Offline

    Delocaz

    Hm, can you catch ClassCastExceptions and re-create the meta?
     
  4. Offline

    caseif

    It's generally not a good idea to catch runtime exceptions. You'll need to recreate the meta when the plugin is reloaded.
     
Thread Status:
Not open for further replies.

Share This Page