Hi Andre, Am 15.10.2010 17:49, schrieb Andre Weihe:
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;
This behavior is surely not by intention. With other words: it is a bug. Could you please file a bug report in our tracking system [1], so that this issue won't get lost.
Thanks. Oliver [1] http://commons.apache.org/configuration/issue-tracking.html --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
