Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-424

HierachicalINIConfiguration has problems with configurations only containing a global section

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • None
    • 1.7
    • Format
    • None

    Description

      HierachicalINIConfiguration#getSections() does not correctly deal with configurations containing only a globalSection() leading for example to a configuration containing only a global section to be saved as a zero length file.

      The current code only acknowledges a global section when at least one other named section is present, if none is present it just returns an empty set.
      Since HierachicalINIConfiguration#save() saves only the contents of the set returned by getSections() this leads to an ini file being loaded and saved again to be saved as a zero length file resulting in the loss of all data in the file (thus the critical priority).

      Workaround:
      Create at least one named section

      Proposed fix (sourcecode):
      Set sections = new ListOrderedSet();

      for (Iterator it = getRootNode().getChildren().iterator(); it.hasNext()
      {
      ConfigurationNode node = (ConfigurationNode) it.next();
      if (isSectionNode(node))

      { sections.add(node.getName()); }

      else

      { sections.add(null); }

      }

      return sections;

      Beware:
      I have NOT tested this (at all).
      It's just the way I would write this method instead of the way it was written before. But since I don't know the big picture maybe there was a (good) reason to write the current version the way it is now so my seemingly easy fix could not work correctly.

      Attachments

        Activity

          People

            oheger Oliver Heger
            lunovus André Weihe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: