java.lang.InstantiationError on all versions except for 1.15

Discussion in 'Spigot Plugin Development' started by craterhater, Jan 7, 2020.

  1. Hey,

    I am trying to get my plugin to run on 1.8+ and an issue I encountered was that when creating a new object it throws a java.lang.InstantiationError. I did some googling and figured out it had to do with constructors and how many parameters it requires. I am still a bit lost and I have yet been unable to solve it. This is where the error occurs:
    Code (Text):
    FancyComponent fancyComponent = new FancyComponent();
    And this is the constructor;
    Code (Text):
    public FancyComponent() {
            fancyDisplayType = FancyDisplayType.DYNAMIC;
        }
    The class does not extend anything.

    This error does not occur on the latest versions. It does, however, occur on 1.9

    EDIT:
    I just realized it only does work on 1.15. All other versions cause this error.

    Thanks!
     
    #1 craterhater, Jan 7, 2020
    Last edited: Jan 7, 2020
  2. MiniDigger

    Supporter

    post the stacktrace please...
    also, post the full class. the ctor isnt the only thing that is run on init, also all field initializer and initializer blocks.

    also, if its 1.8, why do you care?
     
    • Useful Useful x 1
  3. Code (Text):
    package fancyui.craterhater.components;

    import java.util.ArrayList;
    import java.util.List;

    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;

    import fancyui.craterhater.attribute.Attribute;
    import fancyui.craterhater.attribute.AttributeOccasion;
    import fancyui.craterhater.attribute.FunctionParams;
    import fancyui.craterhater.datahandler.DataHandler;
    import fancyui.craterhater.itemstack.FancyItemStack;
    import fancyui.craterhater.itemstack.FancyLore;
    import fancyui.craterhater.masterfancyui.FancyUI;
    import fancyui.craterhater.script.ScriptParser;

    public class FancyComponent {

        //FancyComponent class represents the individual items placed in a FancyUI.
        //It handles things such as animation, itemstack building and event handling whilst
        //allowing the FancyUI to handle loading and deleting of these components.
        //FancyComponents are added to the FancyUI by the user of the API using LoadFunctions.
        //They can also be generated from a FancyUI file.
     
        private FancyLocation fancyLocation;
        private FancyItemStack fancyItemStack;
        private FancyDisplayType fancyDisplayType;
        private String identifier;
        private int ID = 0;
        private int basicSlot = 0;
        private boolean copied = false;
     
        public FancyComponent() {
            fancyDisplayType = FancyDisplayType.DYNAMIC;
        }
     
        public FancyComponent copy(FancyLocation newLocation) {
            FancyComponent newComponent = new FancyComponent();
            newComponent.setDisplayType(fancyDisplayType);
            newComponent.setID(ID);
            newComponent.setFancyItemStack(fancyItemStack);
            newComponent.setFancyLocation(newLocation);
            newComponent.setAttributes(attributes);
            newComponent.setIdentifier(identifier);
            return newComponent;
        }
     
     
        //Method gets called when FancyUI decides to load in new FancyComponents.
        //This happens when openInventory gets called and new components are generated.
        //This method should start future animations. It should also handle ItemStack placement.
        //The boolean here represents whether or not it has succesfully been added. This is used in the
        //FancyUI in order to keep track of all active components and not the once off-screen.
        public boolean addToUI(Inventory inventory, Player p, FileConfiguration fc, FileConfiguration fc2) {
            if(fancyLocation == null) {return false;}
         
            return addToUI(inventory, p, fancyLocation, fc, fc2);
        }
     
        public boolean addToUI(Inventory inventory, Player p, FancyLocation fancyLocation, FileConfiguration fc, FileConfiguration fc2) {
            if(fancyItemStack == null) {return false;}
         
            FancyUI fancyUI = fancyLocation.getFancyUI();
            FancyLocation masterFancyLocation = fancyUI.getFancyData().getCurrentFancyLocation();
         
            if(!fancyLocation.isInView(masterFancyLocation, fancyDisplayType)) {return false;}
         
            int basicSlot = fancyLocation.getBasicLocation(masterFancyLocation.getX(), masterFancyLocation.getY(), fancyDisplayType);
         
            if(basicSlot < 0 || basicSlot >= inventory.getSize()) {return false;}
         
            this.basicSlot = basicSlot;
         
            ItemStack itemStack = fancyItemStack.buildItemStack(p,fc2);
         
            if(fc != null) {
                if(fc.contains("Components."+identifier+".Animations")) {
                    for(String animation : fc.getConfigurationSection("Components."+identifier+".Animations").getKeys(false)) {
                        if(fc.getBoolean(("Components."+identifier+".Animations."+animation+".continious"))){
                            List<String> frames = new ArrayList<>();
                            if(fc.contains("Components."+identifier+".Animations."+animation+".animation")) {
                                frames = fc.getStringList("Components."+identifier+".Animations."+animation+".animation");
                            }
                         
                            int interval = fc.getInt("Components."+identifier+".Animations."+animation+".interval");
                         
                            if(interval < 1) {
                                interval = 2;
                            }
                         
                            int position = fc.getInt("Components."+identifier+".Animations."+animation+".position");
                            boolean continious = fc.getBoolean("Components."+identifier+".Animations."+animation+".continious");
                            boolean reverse = fc.getBoolean("Components."+identifier+".Animations."+animation+".reverse");
                         
                            fancyItemStack.startAnimation(frames, p, interval, position, this, continious, reverse);
                            break;
                        }
                    }
                }
            }
         
            if(fancyLocation.getFancyUI().getFancyData().isPlayerInventory()) {
                if(fancyItemStack.getCustomName().getFancyStringAnimations().length > 0) {
                    fancyItemStack.startAnimation(fancyItemStack.getCustomName().getFancyStringAnimations()[0].getFrames(), p, 4, 0, this, true, false);
                }
            }
         
            inventory.setItem(basicSlot, itemStack);
            return true;
        }
     
        //Method to reload just this component. It is used when cycling through fancyLore. If a function makes changes
        //to other components the reload method in the FancyUI has to be called in order to fully reload a page.
        public void reload(Player p) {
            FileConfiguration fc = DataHandler.getFile(96,p.getUniqueId().toString(), false, "Data", "Users");
            ItemStack itemStack = fancyItemStack.buildItemStack(p,fc);
         
            if(fancyLocation == null) {
                return;
            }
         
            if(fancyLocation.getFancyUI().getFancyData().isPlayerInventory()) {
                p.getInventory().setItem(basicSlot, itemStack);
                return;
            }
         
            fancyLocation.getFancyUI().getFancyData().getInventory().setItem(basicSlot, itemStack);
        }
     
     
        //Method gets called when FancyUI deletes all information on other FancyComponents.
        //This happens when openInventory gets called and new components are generated.
        //Make sure that this method cleans up future animations so they don't go around throwing nullpointers.
        //The ItemStack itself is removed automatically by the FancyUI.
        public void notifyOfDeletion() {
            fancyItemStack.stopAnimating();
        }
     
        //Attributes are pieces of code written by the user of the API in order to have certain things
        //happen at certain events such as ON_CLICK or ON_DROP etc.
        private List<Attribute> attributes = new ArrayList<>();
     
        public void addAttribute(Attribute attribute) {
            attributes.add(attribute);
        }
     
        public List<Attribute> getAttributes(){
            return attributes;
        }
     
        public void setAttributes(List<Attribute> attributes) {
            this.attributes = attributes;
        }
     
        //Method to identify which Attributes need to run at these specific occasions. These occasions
        //may include things suchs as ON_CLICK or ON_1 just to name a few. This method consists of two
        //distinct parts. The first part handles all generated components which have scripts assigned to them
        //and the second part handles all components that have been generated by the plugin itself. And thus
        //do not have scripts assigned to them.
        public void handleEvent(FileConfiguration fc, FileConfiguration fc2, FunctionParams params, AttributeOccasion... attributeOccasions) {
            //The 'identifier' is a tag all generated components get. It is unique to all components.
            //Non-generated components do not have this tag and thus we can check for null to see whether or not
            //it is generated.
            if(identifier != null) {
                if(fc.contains("Components."+identifier+".Scripts")) {
                    for(String script : fc.getConfigurationSection("Components."+identifier+".Scripts").getKeys(false)) {
                        if(fc.contains("Components."+identifier+".Scripts."+script+".events")) {
                            List<String> scriptLines = fc.getStringList("Components."+identifier+".Scripts."+script+".script");
                            for(String event : fc.getStringList("Components."+identifier+".Scripts."+script+".events")) {
                                A: for(AttributeOccasion attributeOccasion : attributeOccasions) {
                                    if(attributeOccasion.name().equalsIgnoreCase(event)) {
                                        fancyLocation.getFancyUI().getScriptParser().executeScript(params.getPlayer(), scriptLines, FancyUI.fancyUI.get(params.getPlayer().getUniqueId()), params.getFancyComponent(), fc2, false);
                                        break A;
                                    }
                                }
                            }
                        }
                    }
                }
             
                if(fc.contains("Components."+identifier+".Animations")) {
                    for(String script : fc.getConfigurationSection("Components."+identifier+".Animations").getKeys(false)) {
                        if(fc.contains("Components."+identifier+".Animations."+script+".events")) {
                            for(String event : fc.getStringList("Components."+identifier+".Animations."+script+".events")) {
                                A: for(AttributeOccasion attributeOccasion : attributeOccasions) {
                                    if(attributeOccasion.name().equalsIgnoreCase(event)) {
                                        List<String> frames = new ArrayList<>();
                                        if(fc.contains("Components."+identifier+".Animations."+script+".animation")) {
                                            frames = fc.getStringList("Components."+identifier+".Animations."+script+".animation");
                                        }
                                     
                                        int interval = fc.getInt("Components."+identifier+".Animations."+script+".interval");
                                     
                                        if(interval < 1) {
                                            interval = 2;
                                        }
                                     
                                        int position = fc.getInt("Components."+identifier+".Animations."+script+".position");
                                     
                                        boolean continious = fc.getBoolean("Components."+identifier+".Animations."+script+".continious");
                                        boolean reverse = fc.getBoolean("Components."+identifier+".Animations."+script+".reverse");
                                        fancyItemStack.startAnimation(frames, params.getPlayer(), interval, position, this, continious, reverse);
                                        break A;
                                    }
                                }
                            }
                        }
                    }
                }
            }
         
            //Handles all components generated by the plugin as well as generated components from file if this component is inside of an editor.
            //If inside an editor generated components will have some attributes linked to them by the plugin. If not inside an editor, generated components
            //will not have any attributes linked to them.
            A:for(Attribute attribute : attributes) {
                for(AttributeOccasion attributeOccasion : attribute.getAttributeOccasions()){
                    for(AttributeOccasion attributeOccasion2 : attributeOccasions) {
                        if(attributeOccasion.equals(attributeOccasion2)) {
                            attribute.getAttributeFunction().call(params);
                            continue A;
                        }
                    }
                }
            }
        }
     
        //This method is used to move the cursor in list cycleables.
        public void performCursorMove(int delta, Player p) {
            if(fancyItemStack == null) {return;}
            FancyLore fancyLore = fancyItemStack.getFancyLore();
            if(fancyLore == null) {return;}
         
            fancyLore.moveCursor(delta, p);
        }
     
        public void setCursorPosition(int n, Player p) {
            if(fancyItemStack == null) {return;}
            FancyLore fancyLore = fancyItemStack.getFancyLore();
            if(fancyLore == null) {return;}
         
            fancyLore.setCursorPosition(n, p);
        }
     
        public int getSlot() {
            return basicSlot;
        }
     
        public FancyLocation getFancyLocation() {
            return fancyLocation;
        }

        public FancyItemStack getFancyItemStack() {
            return fancyItemStack;
        }
     
        public void setFancyItemStack(FancyItemStack fancyItemStack) {
            this.fancyItemStack = fancyItemStack;
        }
     
        public void setFancyLocation(FancyLocation fancyLocation) {
            this.fancyLocation = fancyLocation;
        }
     
        public void setDisplayType(FancyDisplayType fancyDisplayType) {
            this.fancyDisplayType = fancyDisplayType;
        }
     
        public void setIdentifier(String identifier) {
            this.identifier = identifier;
        }
     
        public String getIdentifier() {
            return identifier;
        }
     
        public void setIsCopied(boolean copied) {
            this.copied = copied;
        }
     
        public boolean isCopied() {
            return copied;
        }
     
        public void setID(int ID) {
            this.ID = ID;
        }
     
        public int getID() {
            return ID;
        }
     
        public FancyDisplayType getFancyDisplayType() {
            return fancyDisplayType;
        }
    }
     
    And Stacktrace:
    Code (Text):
    org.bukkit.command.CommandException: Unhandled exception executing command 'fancy' in plugin FancyUI v1.0.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646) ~[1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1115) [1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [1.8.jar:git-Spigot-c3c767f-33d5de3]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_231]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_231]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:696) [1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [1.8.jar:git-Spigot-c3c767f-33d5de3]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]
    Caused by: java.lang.InstantiationError: fancyui.craterhater.components.FancyComponent
            at fancyui.craterhater.uibuilder.ComponentMaker.getComponent(ComponentMaker.java:13) ~[?:?]
            at fancyui.craterhater.uibuilder.Editor_Page_0.getComponents(Editor_Page_0.java:40) ~[?:?]
            at fancyui.craterhater.uibuilder.Editor$1.call(Editor.java:36) ~[?:?]
            at fancyui.craterhater.masterfancyui.FancyUI.openInventory(FancyUI.java:195) ~[?:?]
            at fancyui.craterhater.uibuilder.Editor.createEditorGUI(Editor.java:236) ~[?:?]
            at fancyui.craterhater.commandhandler.MasterCommand$2.call(MasterCommand.java:69) ~[?:?]
            at fancyui.craterhater.commandhandler.CECommand.playerExecutes(CECommand.java:105) ~[?:?]
            at fancyui.craterhater.commandhandler.CECommand.checkPlayerExecutes(CECommand.java:98) ~[?:?]
            at fancyui.craterhater.commandhandler.MasterCommand.onCommand(MasterCommand.java:153) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[1.8.jar:git-Spigot-c3c767f-33d5de3]
            ... 14 more
    >
     
    Here's the class. I care because besides this it takes almost no effort to make this plugin 1.8+ compatible.
     
  4. MiniDigger

    Supporter

    mmmh, interesting. there is no second "Caused by" below that, right?

    the only thing I can see that would be related could be the enum constant, can you just comment out the line in your ctor for a test?
     
  5. Thanks for your suggestion. The error still occurs when the line is commented out. There is no second caused by.
     
  6. What is the component maker class? This error has no way of ocurring within a usual environment, the compiler should catch a change like this. One possibility is that you refer to a particular implementation of something within the bukkit api that is different on 1.8, maybe a different constructor or something.
     
  7. Here is the ComponentMaker class:
    Code (Text):
    public class ComponentMaker {

        public static FancyComponent getComponent(FancyItemStack fancyItemStack, FancyLocation fancyLocation, Attribute... attributes) {
            FancyComponent fancyComponent = new FancyComponent();
         
            FancyLore fancyLore = fancyItemStack.getFancyLore();
            if(fancyLore != null) {
                fancyLore.setFancyComponent(fancyComponent);
            }
         
            fancyComponent.setFancyItemStack(fancyItemStack);
            fancyComponent.setFancyLocation(fancyLocation);
         
            for(Attribute attribute : attributes) {
                fancyComponent.addAttribute(attribute);
            }
         
            return fancyComponent;
        }
    }
    EDIT:
    I just figured out that the plugin thinks my class is abstract;
    Code (Text):
    public abstract class fancyui.craterhater.components.FancyComponent
    But it totally isn't? Why is it doing that. Any ideas?
     
    #7 craterhater, Jan 7, 2020
    Last edited: Jan 7, 2020