Null ConfigurationSection

Discussion in 'Plugin Development' started by DutchJellyV2, Jul 3, 2020.

  1. Offline

    DutchJellyV2

    Hello,

    I encountered another weird issue. Consider the following code:
    Code:
    for(String key : config.getKeys(false)){
        ConfigurationSection subSection = config.getConfigurationSection(key);
        if(subSection == null) Bukkit.getLogger().info("null section found");
    }
    How would it be possible that it finds a null section. My config.yml is similar to this structure:
    Code:
    key:
      ==: blahblah
      anotherkey: anothervalue
    I have no clue why my configurationsection suddenly gets a value of null. The debug output is even showing that it's trying to get the section of 'key'.
     
  2. Offline

    KarimAKL

    @DutchJellyV2 Just because a key with that name exists doesn't mean it's a section, check for that.
     
  3. Offline

    DutchJellyV2

    I think I already found the issue to this problem.

    To give you some more context: I was trying to manually use ConfigurationSerialization.deserializeObject(...) in order to deserialize a section. Appearently, when you use == as a key, it's changing the behavious of getConfigurationSection(..). The deserialization from yamlconfigurations is supposed to be done through a class cast, which solved my issue. So I changed the code to (YourClass)config.get(..).

    Let me know if I need to also explain how I handle serialization using the ConfigurationSerialization class of Spigot in detail!

    Yeah it really was a section, but the built-in serialization seemed to be interfering with my own methods. Thanks for the suggestion anyways! Sometimes you just need to see some different perspectives to the problem to solve it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     

Share This Page