Empty ConfigurationSections created when removing value at end of path

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None

      Hey,
      this is not that big of an 'issue', and I know that this existed since bukkit's beginning, but maybe it might be unintended and improvable nevertheless:

      I am given a bunch of settings each with a certain path and a value. Those values can also be null, to indicate that no value shall be stored and any currently stored value shall get removed from a given config.
      Currently I am simply using config.set(path, value) to set/remove the values as required.

      However, in case of the value being null and the path didn't exist yet in the first place in the config, the above call will create all the empty sections along the path, before trying to remove the value from last section.

      So suddenly, instead of simply making sure that there is no value at a given path, you unintentionally created all those empty config sections along the path instead.

      I know that one could have a special case for those 'null' values, and first check config.contains(path) before trying to remove a value at that path, however, I think the behavior might be more consistent/expectable if the set-method in MemorySection simply wouldn't create any sections along the path in case the intention is to remove a value (in case the value is null).

      The proposed change is as tiny as adding the (value == null)-check before creating new sections:
      [..]
      if (subSection == null) {
      if (value == null) return;
      [..]

            Assignee:
            Unassigned
            Reporter:
            blablubbabc
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: