Are ini files containing only a global section allowed to be used with commons 
configuration, especially the HierachicalINIConfiguration class?

I found no advice in the javadocs that ini files should contain more than just 
a global section but it seems HierachicalINIConfiguration can read those files 
just fine but is not able to save them.

This is due to HierachicalINIConfiguration#getSections() can't really deal with 
those files.

The current code:
        Set sections = new ListOrderedSet();
        boolean globalSection = false;

        for (Iterator it = getRootNode().getChildren().iterator(); 
it.hasNext();)
        {
            ConfigurationNode node = (ConfigurationNode) it.next();
            if (isSectionNode(node))
            {
                if (globalSection)
                {
                    sections.add(null);
                    globalSection = false;
                }
                sections.add(node.getName());
            }
            else
            {
                globalSection = true;
            }
        }

        return sections;


This code only acknowledges a global section when at least one other named 
section is present.

HierachicalINIConfiguration#save() call this functions and only saves sections 
returned by getSections() so if there is only a global section and no other 
sections nothing gets saved.

Is this on purpose or could getSections() be changed to something like this?:

        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;

-- 
André Weihe                            Zengel Medizintechnik GmbH

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to