IllegalArgumentException Not Caught

Discussion in 'Plugin Development' started by Smeary_Subset, Sep 16, 2022.

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

    Smeary_Subset

    I am getting an IllegalArgumentException because I am loading the configuration of a config file that contains locations of unloaded worlds. That's fine, but even though I am try/catching the IllegalArgumentException it still throws the error into the console. Below is my code and the error. You can clearly see that both lines that print out "TEST TEST TEST TEST" are being executed - even the one that comes after the line that throws the crash. However, the catch lines are not printed.

    Code:
        LocationSaver() {
            this.playerLocationFile = new File(MyPlugin.DATA_PATH + "ArenaBuilder/PlayerLocationsBeforeUnload.yml");
            createPlayerLocationFileIfNecessary();
            try {
                System.out.println("TEST TEST TEST TEST");
                this.fileConfig = YamlConfiguration.loadConfiguration(playerLocationFile);
                System.out.println("TEST TEST TEST TEST");
            }
            catch (IllegalArgumentException ignored) {
                System.out.println("ILLEGAL ARGUMENT EXCEPTION");
            }
            catch (Exception ignored) {
                System.out.println("EXCEPTION");
            }
        }

    Code:
    [16:39:52 INFO]: [ArenaBuilder] Disabling ArenaBuilder v${project.version}
    [16:39:52 INFO]: [ArenaBuilder] [STDOUT] TEST TEST TEST TEST
    [16:39:52 ERROR]: [org.bukkit.configuration.serialization.ConfigurationSerialization] Could not call method 'public static org.bukkit.Location org.bukkit.Location.deserialize(java.util.Map)' of class org.bukkit.Location for deserialization
    java.lang.IllegalArgumentException: unknown world
            at org.bukkit.Location.deserialize(Location.java:1139) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[?:?]
            at java.lang.reflect.Method.invoke(Method.java:577) ~[?:?]
            at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeViaMethod(ConfigurationSerialization.java:85) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.serialization.ConfigurationSerialization.deserialize(ConfigurationSerialization.java:127) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject(ConfigurationSerialization.java:207) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:48) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:230) ~[snakeyaml-1.30.jar:?]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:220) ~[snakeyaml-1.30.jar:?]
            at org.bukkit.configuration.file.YamlConstructor.construct(YamlConstructor.java:27) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.YamlConfiguration.fromNodeTree(YamlConfiguration.java:158) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.YamlConfiguration.fromNodeTree(YamlConfiguration.java:156) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:115) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:160) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:128) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:304) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at me.smearysubset.arenabuilder.worldmanagement.LocationSaver.<init>(LocationSaver.java:21) ~[ArenaBuilder.jar:?]
            at me.smearysubset.arenabuilder.worldmanagement.Manager.<init>(Manager.java:19) ~[ArenaBuilder.jar:?]
            at me.smearysubset.arenabuilder.main.MyPlugin.onDisable(MyPlugin.java:32) ~[ArenaBuilder.jar:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:266) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:399) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:579) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:556) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.plugin.SimplePluginManager.clearPlugins(SimplePluginManager.java:634) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.craftbukkit.v1_19_R1.CraftServer.reload(CraftServer.java:980) ~[paper-1.19.1.jar:git-Paper-94]
            at org.bukkit.Bukkit.reload(Bukkit.java:909) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:54) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.craftbukkit.v1_19_R1.CraftServer.dispatchCommand(CraftServer.java:909) ~[paper-1.19.1.jar:git-Paper-94]
            at org.bukkit.craftbukkit.v1_19_R1.CraftServer.dispatchServerCommand(CraftServer.java:872) ~[paper-1.19.1.jar:git-Paper-94]
            at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:473) ~[paper-1.19.1.jar:git-Paper-94]
            at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:447) ~[paper-1.19.1.jar:git-Paper-94]
            at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1415) ~[paper-1.19.1.jar:git-Paper-94]
            at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1191) ~[paper-1.19.1.jar:git-Paper-94]
            at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:305) ~[paper-1.19.1.jar:git-Paper-94]
            at java.lang.Thread.run(Thread.java:833) ~[?:?]
    [16:39:52 INFO]: [ArenaBuilder] [STDOUT] TEST TEST TEST TEST
    [16:39:52 INFO]: [SurvivalEnhancer] Disabling SurvivalEnhancer v1.0-SNAPSHOT
    [16:39:52 INFO]: [GunGame] Disabling GunGame v1.0
    [16:39:52 INFO]: [Skyblock] Disabling Skyblock v1.0-SNAPSHOT
    
     
  2. Offline

    CraftCreeper6

    You have another post about this, I haven't checked them exactly but they both relate to worlds, is this the same issue?
    https://bukkit.org/threads/illegalargumentexception.496029/
     
  3. Offline

    Smeary_Subset

    Oh yeah, forgot I posted that. It's not the same code but similar. Nevertheless, the issue persists (even the one from the last post). In the last post, I was more wondering why the error was being thrown as opposing to focusing on the try\catch. It actually never got fixed, timtower just clarified why it was occurring.

    Do you (or anyone) have any idea why the error isn't being caught? I really would prefer the error to not print to the console.
     
  4. Offline

    CraftCreeper6

    Error likely isn't implicitly caused by calling loadConfiguration. See here.

    It's strange that line of code is even throwing that error since it has no relevance to worlds at all. I guess there's some internal stuff that parses Yaml for use later (????? haven't looked) which includes worlds, unless you've cut some code out?

    But in any case, take a look through the source code that I linked above and see if you can find the problem there.
     
  5. Offline

    Smeary_Subset

    So, I've made some progress. What's throwing IllegalArgumentException isn't the YamlConfiguration but rather the Location class trying to deserialize the location. This doesn't change my question as to why it is unable to be caught. But atleast we know it doesn't have to do with the YAML Configuration method.

    And you can see that this is the case by looking at the top of the stack trace. And if you look at Location.deserialize() in the javadocs, you can clearly see that it throws IllegalArgumentException when the world does not exist.
     
    Last edited: Sep 18, 2022
Thread Status:
Not open for further replies.

Share This Page