Hello Thomas,
You might want to look at the unit tests to see if there are any
expectations regarding empty section names. I don't know off the top of my
head.
Gary
On Mon, Apr 15, 2024, 11:41 AM Steiner Thomas
wrote:
> Hi,
>
> should it possible to parse an ini-File with an empty section key with
> commons-configuration2 2.10.1?
>
> Or is there any intended purpose why the following example doesn't work:
> INIConfiguration iniConfiguration = new INIConfiguration();
> try (FileReader fileReader = new FileReader(file)) {
> iniConfiguration.read(fileReader);
> } catch (ConfigurationException | IOException e) {
> e.printStackTrace();
> }
> SubnodeConfiguration subSection = iniConfiguration.getSection("");
> String nextKey = subSection.getKeys().next();
> assertNotNull(nextKey);
> assertEquals("property", nextKey);
> Object nextValue = subSection.getProperty(nextKey);
> assertNotNull(nextValue); // FIXME: value is null
> assertEquals("property1", nextValue);
>
> emptySection.ini:
> []
> property = "property1"
>
> The value is null due to the keyBuffer's length in the
> DefaultConfigurationKey is 0 and the endIndex is also 0 so the
> KeyIterator's hasNext() is false.
>
> Sections with a space (' ') are parsed as expected:
> INIConfiguration iniConfiguration = new INIConfiguration();
> try (FileReader fileReader = new FileReader(file)) {
> iniConfiguration.read(fileReader);
> } catch (ConfigurationException | IOException e) {
> e.printStackTrace();
> }
> SubnodeConfiguration subSection = iniConfiguration.getSection(" ");
> String nextKey = subSection.getKeys().next();
> assertNotNull(nextKey);
> assertEquals("property", nextKey);
> Object nextValue = subSection.getProperty(nextKey);
> assertNotNull(nextValue);
> assertEquals("property1", nextValue);
>
> spaceSection.ini:
> [ ]
> property = "property1"
>
> Best regards,
> Thomas Steiner
>
>
>
> Please note the information on data protection at
> https://www.engelglobal.com/dataprotection.
>
>
>
>
> Important Notice:
> This electronic transmission (including any attachments) is intended
> solely for the use and information
> of the addressee(s). It may contain confidential or legally privileged
> information. Any unauthorized use
> or disclosure of this message is strictly prohibited.If you are not the
> intended recipient, please notify
> the sender immediately and delete the message and its attachments.
> The sender does not guarantee the integrity of this transmission and shall
> therefore never be liable if
> the message is altered or falsified nor for any virus, interception or
> damage to your system.
>