[Solved] Stack Overflow help!

Discussion in 'Plugin Development' started by FurmigaHumana, Jun 16, 2012.

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

    FurmigaHumana

    I'm get this error when my plugin load, but it just happens on Unix, in my pc [win 7] runs fine.

    Error:
    Code:
    [SEVERE] Error occurred while enabling CreativeControl v4.3 (Is it up to date?)
    java.lang.StackOverflowError
    at java.io.UnixFileSystem.getBooleanAttributes0(Native Method)
    at java.io.UnixFileSystem.getBooleanAttributes(Unknown Source)
    at java.io.File.exists(Unknown Source)
    at me.FurH.CreativeControl.configuration.CreativeConfiguration.getMessage(CreativeConfiguration.java:61)
    at me.FurH.CreativeControl.util.CreativeCommunicator.format(CreativeCommunicator.java:26)
    at me.FurH.CreativeControl.util.CreativeCommunicator.log(CreativeCommunicator.java:61)
    at me.FurH.CreativeControl.configuration.CreativeConfiguration.getMessage(CreativeConfiguration.java:68)
    at me.FurH.CreativeControl.util.CreativeCommunicator.format(CreativeCommunicator.java:26)
    at me.FurH.CreativeControl.util.CreativeCommunicator.log(CreativeCommunicator.java:61)
    
    Code: CreativeConfiguration.java Line 61
    Code:
        public String getMessage(String value) {
            if (msg.containsKey(value)) {
                return msg.get(value);
            } else {
                CreativeControl plugin = CreativeControl.getPlugin();
                CreativeCommunicator com = CreativeControl.getCom();
                YamlConfiguration config = new YamlConfiguration();
                File dir = new File(plugin.getDataFolder(), "messages.yml");
                if (!dir.exists()) { //Line 61
                    CreativeUtil.ccFile(plugin.getResource("messages.yml"), dir);
                }
     
                try {
                    config.load(dir);
                } catch (IOException | InvalidConfigurationException ex) {
                    com.log("[TAG] Can't load the Messages File: {0}", LogType.LOG_SEVERE, ex.getMessage()); //Line 68
                    if (plugin.isDebug()) { ex.printStackTrace(); }
                }
               
                if (!config.contains(value)) {
                    config.set(value, value);
                    try {
                        config.save(dir);
                    } catch (IOException ex) {
                        com.log("[TAG] Can't save the Messages File: {0}", LogType.LOG_SEVERE, ex.getMessage());
                        if (plugin.isDebug()) { ex.printStackTrace(); }
                    }
                }
     
                String string = config.getString(value);
                msg.put(value, string);
                return string;
            }
        }
    CreativeCommunicator.java: http://pastebin.com/arN2stHV
    File Copy: http://pastebin.com/B3u9qnmX

    Someone know what I doing wrong?
     
  2. Offline

    hatstand

    It looks like getMessage calls log which calls format which calls getMessage and so on, repeating until it finally gets to the file.exists call, at which point, the stack overflows. That should only be an issue if your plugin repeats the getMessage/log/format loop dozens, if not hundreds of times.

    If it's doing that due to repeatedly catching an exception, which seems likely, put in some kind of failsafe that gets tripped after the first exception is caught, stopping it from happening again.
     
  3. Offline

    FurmigaHumana

    It makes perfect sense, the server.log had 1025 lines with this error.

    I'll see what I can do now.

    //Update
    This fixed the loop, what you think?

    Code:
        public String getMessage(String node) {
            if (msg.containsKey(node)) {
                return msg.get(node);
            } else {
                CreativeControl plugin = CreativeControl.getPlugin();
                YamlConfiguration config = new YamlConfiguration();
               
                File dir = new File(plugin.getDataFolder(), "messages.yml");
                if (!dir.exists()) { CreativeUtil.ccFile(plugin.getResource("messages.yml"), dir); }
               
                try {
                    config.load(dir);
                    if (!config.contains(node)) {
                        config.set(node, node);
                        try {
                            config.save(dir);
                           
                            String string = config.getString(node);
                            msg.put(node, string);
                            return string;
                        } catch (IOException ex) {
                            CreativeControl.logger.severe("[CreativeControl] Can't save the Messages File: "+ ex.getMessage());
                            if (plugin.isDebug()) { ex.printStackTrace(); }
                        }
                    } else {
                        String string = config.getString(node);
                        msg.put(node, string);
                        return string;
                    }
                } catch (IOException ex) {
                    CreativeControl.logger.severe("[CreativeControl] Can't load the Messages File: "+ ex.getMessage());
                    if (plugin.isDebug()) { ex.printStackTrace(); }
                } catch (InvalidConfigurationException ex) {
                    CreativeControl.logger.severe("[CreativeControl]: "+ ex.getMessage());
                }
                return "";
            }
        }
     
  4. Offline

    hatstand

    That looks like it should
     
    FurmigaHumana likes this.
  5. Offline

    FurmigaHumana

    Thanks for your help :)
     
Thread Status:
Not open for further replies.

Share This Page