Solved "java.lang.IllegalArgumentException: Specified class does not exist" But it does

Discussion in 'Plugin Development' started by Conarnar, Nov 7, 2013.

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


    I'm trying to make a kit plugin that uses ConfigurationSerializable to save inventories.
    When I try to load a configuration file, this happens.
    2013-11-07 19:22:29 [SEVERE] Cannot load plugins\MorangeKits\kits.yml
    org.bukkit.configuration.InvalidConfigurationException: org.yaml.snakeyaml.error.YAMLException: Could not deserialize object
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(
        at org.bukkit.configuration.file.FileConfiguration.load(
        at org.bukkit.configuration.file.FileConfiguration.load(
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(
        at me.conarnar.morangekits.MorangeKits.onEnable(
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugin(
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.enablePlugins(
        at net.minecraft.server.v1_6_R3.MinecraftServer.l(
        at net.minecraft.server.v1_6_R3.MinecraftServer.f(
        at net.minecraft.server.v1_6_R3.MinecraftServer.a(
        at net.minecraft.server.v1_6_R3.DedicatedServer.init(
    Caused by: org.yaml.snakeyaml.error.YAMLException: Could not deserialize object
        at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(
        at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(
        at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(
        at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(
        at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(
        at org.yaml.snakeyaml.Yaml.loadFromReader(
        at org.yaml.snakeyaml.Yaml.load(
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(
        ... 15 more
    Caused by: java.lang.IllegalArgumentException: Specified class does not exist ('me.conarnar.morangekits.InventoryWrapper')
        at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject(
        at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(
        ... 27 more
    It says
    Caused by: java.lang.IllegalArgumentException: Specified class does not exist ('me.conarnar.morangekits.InventoryWrapper')
    but that class does exist.
    package me.conarnar.morangekits;
    import java.util.HashMap;
    import java.util.Map;
    import org.bukkit.configuration.serialization.ConfigurationSerializable;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    public class InventoryWrapper implements ConfigurationSerializable {
        private final ItemStack[] contents;
        private final ItemStack[] armorContents;
        public InventoryWrapper(PlayerInventory inv) {
            this(inv.getContents(), inv.getArmorContents());
        protected InventoryWrapper(ItemStack[] stack1, ItemStack[] stack2) {
            contents = stack1;
            armorContents = stack2;
        public Map<String, Object> serialize() {
            Map<String, Object> map = new HashMap<String, Object>();
            for (int slot = 0; slot < contents.length; slot++) {
                if (contents[slot] != null) {
                    map.put(String.valueOf(slot), contents[slot]);
            for (int slot = 0; slot < armorContents.length; slot++) {
                if (armorContents[slot] != null) {
                    map.put("armor" + slot, armorContents[slot]);
            return map;
        public static InventoryWrapper deserialize(Map<String, Object> map) {
            ItemStack[] stack1 = new ItemStack[36];
            ItemStack[] stack2 = new ItemStack[4];
            for (int slot = 0; slot < stack1.length; slot++) {
                stack1[slot] = (ItemStack) map.get(String.valueOf(slot));
            for (int slot = 0; slot < stack2.length; slot++) {
                stack2[slot] = (ItemStack) map.get("armor" + slot);
            return new InventoryWrapper(stack1, stack2);
        public void setPlayerInventory(Player player) {
  2. Offline


    I had this error before, have you registered the class ? Put this in your onEnable() (I read you should put it in the actual class in static {}, though that didn't work for me :()
  3. Offline


    Oh yeah, I forgot all about that. I'll try that later to see if it works.
  4. Offline

    Wolvereness Bukkit Team Member

    Use onLoad() for registering serializable classes... static{} is initiated before your plugin even exists, and action there would result in strange classloader leaks.
    Hellgast likes this.
  5. Offline

    1Rogue Retired Staff

    Question on ordering of that, do static blocks have same initialization time as fields?
  6. Offline


    Still same thing happening.
    1. public void onEnable() {
    2. getServer().getPluginManager().registerEvents(this, this);
    4. Command command = getCommand("mkit");
    5. command.setUsage("/mkit [create|delete] <kitname>");
    7. kitsFile = new File(getDataFolder(), "kits.yml");
    8. kits = YamlConfiguration.loadConfiguration(kitsFile);
    9. ConfigurationSerialization.registerClass(InventoryWrapper.class);
    10. }

    Oh wait I think I see the problem.
    1. kits = YamlConfiguration.loadConfiguration(kitsFile);
    2. ConfigurationSerialization.registerClass(InventoryWrapper.class);

    I should have put ConfigurationSerialization.registerClass(InventoryWrapper.class) above that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 5, 2016
  7. Offline


    Glad I found this. It solved my problem too after several hours of head scratching. What's really weird is that I had not registered any of my serializable classes (one superclass and 4 subclasses). Serialization went flawlessly for all classes. However when deserializing I got the error when attempting to access one of the sub classes. Only one. If I didn't have that class in my config it worked fine. I did have to register all of my classes to get it to get that one class to work properly.
    Hellgast likes this.
Thread Status:
Not open for further replies.

Share This Page