[configuration] Problem with XMLConfiguration.setProperty(String, Object) and setDelimiterParsingDisabled

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[configuration] Problem with XMLConfiguration.setProperty(String, Object) and setDelimiterParsingDisabled

thc202
Hi.

After reading the topic "List handling" in the page "Basic Features" (
https://commons.apache.org/configuration/userguide/howto_basicfeatures.html#List_handling),
I understand that when setting a List with the method setProperty(String,
Object), the state of the delimiterParsingDisabled wouldn't affect how the
List is saved, that it only applies to objects String.

But with a XMLConfiguration (the one that I use) depending on the state of
the delimiter parsing option the List is saved differently. Is this the
expected behaviour?

I've set up an example to show what is happening, I've used the version 1.8
of the commons-configuration (but it also happens with the version 1.6).

For running the example are needed 3 files ("DelimiterExample.java",
"ConfDelimiterEnabled.xml" and "ConfDelimiterDisabled.xml"), all in the
same directory.

Contents of DelimiterExample.java :

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;

public class DelimiterExample
{
  // Configuration file that will have the setDelimiterParsingDisabled as
_false_.
  private static final String CONF_DELIMITER_ENABLED_XML =
"ConfDelimiterEnabled.xml";

  // Configuration file that will have the setDelimiterParsingDisabled as
_true_.
  private static final String CONF_DELIMITER_DISABLED_XML =
"ConfDelimiterDisabled.xml";

  // Key of the data used in the configuration files.
  private static final String LIST_ELEMENT_KEY = "list.element";

  public static void main(String[] args) throws ConfigurationException
  {
    // Data that will be saved in the configuration files.
    List<String> data = new ArrayList<String>(3);
    data.add("value 1");
    data.add("value 2");
    data.add("value 3");


    // First using setDelimiterParsingDisabled as false.

    XMLConfiguration confDelimiterEnabledWrite = new
XMLConfiguration(CONF_DELIMITER_ENABLED_XML);

    confDelimiterEnabledWrite.setProperty(LIST_ELEMENT_KEY, data); //
Writes:
    // <list>
    // <element>value 1</element>
    // <element>value 2</element>
    // <element>value 3</element>
    // </list>

    confDelimiterEnabledWrite.save();

    XMLConfiguration confDelimiterEnabledRead = new
XMLConfiguration(CONF_DELIMITER_ENABLED_XML);
    String[] values =
confDelimiterEnabledRead.getStringArray(LIST_ELEMENT_KEY);

    // Doesn't output anything as they are equals. Expected behaviour.
    if (!Arrays.equals(values, data.toArray()))
    {
      System.out.println("setDelimiterParsingDisabled(false): Data not
equal!");
    }


    // Now using setDelimiterParsingDisabled as true.

    XMLConfiguration confDelimiterDisabledWrite = new XMLConfiguration();
    confDelimiterDisabledWrite.setDelimiterParsingDisabled(true);
    confDelimiterDisabledWrite.setFileName(CONF_DELIMITER_DISABLED_XML);
    confDelimiterDisabledWrite.load();

    confDelimiterDisabledWrite.setProperty(LIST_ELEMENT_KEY, data); //
Writes:
    // <list>
    // <element>[value 1, value 2, value 3]</element>
    // </list>

    // Unexpected behaviour!
    // Shouldn't it write the same as with setDelimiterParsingDisabled as
false?
    // as it is a list.

    confDelimiterDisabledWrite.save();

    XMLConfiguration confDelimiterDisabledRead = new XMLConfiguration();
    confDelimiterDisabledRead.setDelimiterParsingDisabled(true);
    confDelimiterDisabledRead.setFileName(CONF_DELIMITER_DISABLED_XML);
    confDelimiterDisabledRead.load();

    values = confDelimiterDisabledRead.getStringArray(LIST_ELEMENT_KEY);

    // As it writes other thing this will output that they are not equals.
    if (!Arrays.equals(values, data.toArray()))
    {
      System.out.println("setDelimiterParsingDisabled(true): Data not
equal!");
    }
  }

}



Both "ConfDelimiterEnabled.xml" and "ConfDelimiterDisabled.xml" have the
same content:

<?xml version="1.0" encoding="UTF-8"?>
<config>
</config>


Let me know if there is something that is missing/wrong.

Best regards.
Reply | Threaded
Open this post in threaded view
|

Re: [configuration] Problem with XMLConfiguration.setProperty(String, Object) and setDelimiterParsingDisabled

thc202
Hi.

Sorry for the code not properly indented (content of DelimiterExample.java).

Here it goes again:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;

public class DelimiterExample
{
  // Configuration file that will have the
  // setDelimiterParsingDisabled as _false_.
  private static final String CONF_DELIMITER_ENABLED_XML =
    "ConfDelimiterEnabled.xml";

  // Configuration file that will have the
  // setDelimiterParsingDisabled as_true_.
  private static final String CONF_DELIMITER_DISABLED_XML =
    "ConfDelimiterDisabled.xml";

  // Key of the data used in the configuration files.
  private static final String LIST_ELEMENT_KEY = "list.element";

  public static void main(String[] args) throws ConfigurationException
  {
    // Data that will be saved in the configuration files.
    List<String> data = new ArrayList<String>(3);
    data.add("value 1");
    data.add("value 2");
    data.add("value 3");


    // First using setDelimiterParsingDisabled as false.

    XMLConfiguration confDelimiterEnabledWrite =
      new XMLConfiguration(CONF_DELIMITER_ENABLED_XML);

    confDelimiterEnabledWrite.setProperty(LIST_ELEMENT_KEY, data);
    // Writes:
    //  <list>
    //  <element>value 1</element>
    //  <element>value 2</element>
    //  <element>value 3</element>
    //  </list>

    confDelimiterEnabledWrite.save();

    XMLConfiguration confDelimiterEnabledRead =
      new XMLConfiguration(CONF_DELIMITER_ENABLED_XML);
    String[] values =
      confDelimiterEnabledRead.getStringArray(LIST_ELEMENT_KEY);

    // Doesn't output anything as they are equals. Expected behaviour.
    if (!Arrays.equals(values, data.toArray()))
    {
      System.out.println(
        "setDelimiterParsingDisabled(false): Data not equal!");
    }


    // Now using setDelimiterParsingDisabled as true.

    XMLConfiguration confDelimiterDisabledWrite = new XMLConfiguration();
    confDelimiterDisabledWrite.setDelimiterParsingDisabled(true);
    confDelimiterDisabledWrite.setFileName(CONF_DELIMITER_DISABLED_XML);
    confDelimiterDisabledWrite.load();

    confDelimiterDisabledWrite.setProperty(LIST_ELEMENT_KEY, data);
    // Writes:
    //  <list>
    //  <element>[value 1, value 2, value 3]</element>
    //  </list>

    // Unexpected behaviour!
    // Shouldn't it write the same as with
    // setDelimiterParsingDisabled as false? as it is a list.

    confDelimiterDisabledWrite.save();

    XMLConfiguration confDelimiterDisabledRead = new XMLConfiguration();
    confDelimiterDisabledRead.setDelimiterParsingDisabled(true);
    confDelimiterDisabledRead.setFileName(CONF_DELIMITER_DISABLED_XML);
    confDelimiterDisabledRead.load();

    values = confDelimiterDisabledRead.getStringArray(LIST_ELEMENT_KEY);

    // As it writes other thing this will output that they are not equals.
    if (!Arrays.equals(values, data.toArray()))
    {
      System.out.println(
        "setDelimiterParsingDisabled(true): Data not equal!");
    }
  }

}


Best regards.
Reply | Threaded
Open this post in threaded view
|

Re: [configuration] Problem with XMLConfiguration.setProperty(String, Object) and setDelimiterParsingDisabled

Oliver Heger-3
Thank you for reporting this. I agree with you that the output of the
configuration should be independent on the value of the delimiter
parsing flag.

If you are convinced that this is an error, please open a ticket in our
bug tracking system [1].

I hope to find some time in the next days to have a look at this issue.

Oliver

[1] http://commons.apache.org/configuration/issue-tracking.html

Am 22.04.2012 13:38, schrieb [hidden email]:

> Hi.
>
> Sorry for the code not properly indented (content of DelimiterExample.java).
>
> Here it goes again:
>
> import java.util.ArrayList;
> import java.util.Arrays;
> import java.util.List;
>
> import org.apache.commons.configuration.ConfigurationException;
> import org.apache.commons.configuration.XMLConfiguration;
>
> public class DelimiterExample
> {
>    // Configuration file that will have the
>    // setDelimiterParsingDisabled as _false_.
>    private static final String CONF_DELIMITER_ENABLED_XML =
>      "ConfDelimiterEnabled.xml";
>
>    // Configuration file that will have the
>    // setDelimiterParsingDisabled as_true_.
>    private static final String CONF_DELIMITER_DISABLED_XML =
>      "ConfDelimiterDisabled.xml";
>
>    // Key of the data used in the configuration files.
>    private static final String LIST_ELEMENT_KEY = "list.element";
>
>    public static void main(String[] args) throws ConfigurationException
>    {
>      // Data that will be saved in the configuration files.
>      List<String>  data = new ArrayList<String>(3);
>      data.add("value 1");
>      data.add("value 2");
>      data.add("value 3");
>
>
>      // First using setDelimiterParsingDisabled as false.
>
>      XMLConfiguration confDelimiterEnabledWrite =
>        new XMLConfiguration(CONF_DELIMITER_ENABLED_XML);
>
>      confDelimiterEnabledWrite.setProperty(LIST_ELEMENT_KEY, data);
>      // Writes:
>      //<list>
>      //<element>value 1</element>
>      //<element>value 2</element>
>      //<element>value 3</element>
>      //</list>
>
>      confDelimiterEnabledWrite.save();
>
>      XMLConfiguration confDelimiterEnabledRead =
>        new XMLConfiguration(CONF_DELIMITER_ENABLED_XML);
>      String[] values =
>        confDelimiterEnabledRead.getStringArray(LIST_ELEMENT_KEY);
>
>      // Doesn't output anything as they are equals. Expected behaviour.
>      if (!Arrays.equals(values, data.toArray()))
>      {
>        System.out.println(
>          "setDelimiterParsingDisabled(false): Data not equal!");
>      }
>
>
>      // Now using setDelimiterParsingDisabled as true.
>
>      XMLConfiguration confDelimiterDisabledWrite = new XMLConfiguration();
>      confDelimiterDisabledWrite.setDelimiterParsingDisabled(true);
>      confDelimiterDisabledWrite.setFileName(CONF_DELIMITER_DISABLED_XML);
>      confDelimiterDisabledWrite.load();
>
>      confDelimiterDisabledWrite.setProperty(LIST_ELEMENT_KEY, data);
>      // Writes:
>      //<list>
>      //<element>[value 1, value 2, value 3]</element>
>      //</list>
>
>      // Unexpected behaviour!
>      // Shouldn't it write the same as with
>      // setDelimiterParsingDisabled as false? as it is a list.
>
>      confDelimiterDisabledWrite.save();
>
>      XMLConfiguration confDelimiterDisabledRead = new XMLConfiguration();
>      confDelimiterDisabledRead.setDelimiterParsingDisabled(true);
>      confDelimiterDisabledRead.setFileName(CONF_DELIMITER_DISABLED_XML);
>      confDelimiterDisabledRead.load();
>
>      values = confDelimiterDisabledRead.getStringArray(LIST_ELEMENT_KEY);
>
>      // As it writes other thing this will output that they are not equals.
>      if (!Arrays.equals(values, data.toArray()))
>      {
>        System.out.println(
>          "setDelimiterParsingDisabled(true): Data not equal!");
>      }
>    }
>
> }
>
>
> Best regards.
>


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

Reply | Threaded
Open this post in threaded view
|

Re: [configuration] Problem with XMLConfiguration.setProperty(String, Object) and setDelimiterParsingDisabled

Oliver Heger-3
Am 22.04.2012 22:15, schrieb Oliver Heger:
> Thank you for reporting this. I agree with you that the output of the
> configuration should be independent on the value of the delimiter
> parsing flag.
>
> If you are convinced that this is an error, please open a ticket in our
> bug tracking system [1].
>
> I hope to find some time in the next days to have a look at this issue.

This is indeed a bug. It actually affects all Configuration implementations.

I opened the following bug report:
https://issues.apache.org/jira/browse/CONFIGURATION-495

Oliver

>
> Oliver
>
> [1] http://commons.apache.org/configuration/issue-tracking.html
>
> Am 22.04.2012 13:38, schrieb [hidden email]:
>> Hi.
>>
>> Sorry for the code not properly indented (content of
>> DelimiterExample.java).
>>
>> Here it goes again:
>>
>> import java.util.ArrayList;
>> import java.util.Arrays;
>> import java.util.List;
>>
>> import org.apache.commons.configuration.ConfigurationException;
>> import org.apache.commons.configuration.XMLConfiguration;
>>
>> public class DelimiterExample
>> {
>> // Configuration file that will have the
>> // setDelimiterParsingDisabled as _false_.
>> private static final String CONF_DELIMITER_ENABLED_XML =
>> "ConfDelimiterEnabled.xml";
>>
>> // Configuration file that will have the
>> // setDelimiterParsingDisabled as_true_.
>> private static final String CONF_DELIMITER_DISABLED_XML =
>> "ConfDelimiterDisabled.xml";
>>
>> // Key of the data used in the configuration files.
>> private static final String LIST_ELEMENT_KEY = "list.element";
>>
>> public static void main(String[] args) throws ConfigurationException
>> {
>> // Data that will be saved in the configuration files.
>> List<String> data = new ArrayList<String>(3);
>> data.add("value 1");
>> data.add("value 2");
>> data.add("value 3");
>>
>>
>> // First using setDelimiterParsingDisabled as false.
>>
>> XMLConfiguration confDelimiterEnabledWrite =
>> new XMLConfiguration(CONF_DELIMITER_ENABLED_XML);
>>
>> confDelimiterEnabledWrite.setProperty(LIST_ELEMENT_KEY, data);
>> // Writes:
>> //<list>
>> //<element>value 1</element>
>> //<element>value 2</element>
>> //<element>value 3</element>
>> //</list>
>>
>> confDelimiterEnabledWrite.save();
>>
>> XMLConfiguration confDelimiterEnabledRead =
>> new XMLConfiguration(CONF_DELIMITER_ENABLED_XML);
>> String[] values =
>> confDelimiterEnabledRead.getStringArray(LIST_ELEMENT_KEY);
>>
>> // Doesn't output anything as they are equals. Expected behaviour.
>> if (!Arrays.equals(values, data.toArray()))
>> {
>> System.out.println(
>> "setDelimiterParsingDisabled(false): Data not equal!");
>> }
>>
>>
>> // Now using setDelimiterParsingDisabled as true.
>>
>> XMLConfiguration confDelimiterDisabledWrite = new XMLConfiguration();
>> confDelimiterDisabledWrite.setDelimiterParsingDisabled(true);
>> confDelimiterDisabledWrite.setFileName(CONF_DELIMITER_DISABLED_XML);
>> confDelimiterDisabledWrite.load();
>>
>> confDelimiterDisabledWrite.setProperty(LIST_ELEMENT_KEY, data);
>> // Writes:
>> //<list>
>> //<element>[value 1, value 2, value 3]</element>
>> //</list>
>>
>> // Unexpected behaviour!
>> // Shouldn't it write the same as with
>> // setDelimiterParsingDisabled as false? as it is a list.
>>
>> confDelimiterDisabledWrite.save();
>>
>> XMLConfiguration confDelimiterDisabledRead = new XMLConfiguration();
>> confDelimiterDisabledRead.setDelimiterParsingDisabled(true);
>> confDelimiterDisabledRead.setFileName(CONF_DELIMITER_DISABLED_XML);
>> confDelimiterDisabledRead.load();
>>
>> values = confDelimiterDisabledRead.getStringArray(LIST_ELEMENT_KEY);
>>
>> // As it writes other thing this will output that they are not equals.
>> if (!Arrays.equals(values, data.toArray()))
>> {
>> System.out.println(
>> "setDelimiterParsingDisabled(true): Data not equal!");
>> }
>> }
>>
>> }
>>
>>
>> Best regards.
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


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

Reply | Threaded
Open this post in threaded view
|

Re: [configuration] Problem with XMLConfiguration.setProperty(String, Object) and setDelimiterParsingDisabled

thc202
Hi.

Sorry for not answering sooner.

>I opened the following bug report:
>https://issues.apache.org/jira/browse/CONFIGURATION-495
OK, thank you. I meant to do it but I had to create an account first.

Thank you for your prompt replies and for looking into it.

Best regards.

On 25 April 2012 21:16, Oliver Heger <[hidden email]> wrote:

> Am 22.04.2012 22:15, schrieb Oliver Heger:
>
>  Thank you for reporting this. I agree with you that the output of the
>> configuration should be independent on the value of the delimiter
>> parsing flag.
>>
>> If you are convinced that this is an error, please open a ticket in our
>> bug tracking system [1].
>>
>> I hope to find some time in the next days to have a look at this issue.
>>
>
> This is indeed a bug. It actually affects all Configuration
> implementations.
>
> I opened the following bug report:
> https://issues.apache.org/**jira/browse/CONFIGURATION-495<https://issues.apache.org/jira/browse/CONFIGURATION-495>
>
> Oliver
>
>
>
>> Oliver
>>
>> [1] http://commons.apache.org/**configuration/issue-tracking.**html<http://commons.apache.org/configuration/issue-tracking.html>
>>
>> Am 22.04.2012 13:38, schrieb [hidden email]:
>>
>>> Hi.
>>>
>>> Sorry for the code not properly indented (content of
>>> DelimiterExample.java).
>>>
>>> Here it goes again:
>>>
>>> import java.util.ArrayList;
>>> import java.util.Arrays;
>>> import java.util.List;
>>>
>>> import org.apache.commons.**configuration.**ConfigurationException;
>>> import org.apache.commons.**configuration.**XMLConfiguration;
>>>
>>> public class DelimiterExample
>>> {
>>> // Configuration file that will have the
>>> // setDelimiterParsingDisabled as _false_.
>>> private static final String CONF_DELIMITER_ENABLED_XML =
>>> "ConfDelimiterEnabled.xml";
>>>
>>> // Configuration file that will have the
>>> // setDelimiterParsingDisabled as_true_.
>>> private static final String CONF_DELIMITER_DISABLED_XML =
>>> "ConfDelimiterDisabled.xml";
>>>
>>> // Key of the data used in the configuration files.
>>> private static final String LIST_ELEMENT_KEY = "list.element";
>>>
>>> public static void main(String[] args) throws ConfigurationException
>>> {
>>> // Data that will be saved in the configuration files.
>>> List<String> data = new ArrayList<String>(3);
>>> data.add("value 1");
>>> data.add("value 2");
>>> data.add("value 3");
>>>
>>>
>>> // First using setDelimiterParsingDisabled as false.
>>>
>>> XMLConfiguration confDelimiterEnabledWrite =
>>> new XMLConfiguration(CONF_**DELIMITER_ENABLED_XML);
>>>
>>> confDelimiterEnabledWrite.**setProperty(LIST_ELEMENT_KEY, data);
>>> // Writes:
>>> //<list>
>>> //<element>value 1</element>
>>> //<element>value 2</element>
>>> //<element>value 3</element>
>>> //</list>
>>>
>>> confDelimiterEnabledWrite.**save();
>>>
>>> XMLConfiguration confDelimiterEnabledRead =
>>> new XMLConfiguration(CONF_**DELIMITER_ENABLED_XML);
>>> String[] values =
>>> confDelimiterEnabledRead.**getStringArray(LIST_ELEMENT_**KEY);
>>>
>>> // Doesn't output anything as they are equals. Expected behaviour.
>>> if (!Arrays.equals(values, data.toArray()))
>>> {
>>> System.out.println(
>>> "setDelimiterParsingDisabled(**false): Data not equal!");
>>> }
>>>
>>>
>>> // Now using setDelimiterParsingDisabled as true.
>>>
>>> XMLConfiguration confDelimiterDisabledWrite = new XMLConfiguration();
>>> confDelimiterDisabledWrite.**setDelimiterParsingDisabled(**true);
>>> confDelimiterDisabledWrite.**setFileName(CONF_DELIMITER_**DISABLED_XML);
>>> confDelimiterDisabledWrite.**load();
>>>
>>> confDelimiterDisabledWrite.**setProperty(LIST_ELEMENT_KEY, data);
>>> // Writes:
>>> //<list>
>>> //<element>[value 1, value 2, value 3]</element>
>>> //</list>
>>>
>>> // Unexpected behaviour!
>>> // Shouldn't it write the same as with
>>> // setDelimiterParsingDisabled as false? as it is a list.
>>>
>>> confDelimiterDisabledWrite.**save();
>>>
>>> XMLConfiguration confDelimiterDisabledRead = new XMLConfiguration();
>>> confDelimiterDisabledRead.**setDelimiterParsingDisabled(**true);
>>> confDelimiterDisabledRead.**setFileName(CONF_DELIMITER_**DISABLED_XML);
>>> confDelimiterDisabledRead.**load();
>>>
>>> values = confDelimiterDisabledRead.**getStringArray(LIST_ELEMENT_**KEY);
>>>
>>> // As it writes other thing this will output that they are not equals.
>>> if (!Arrays.equals(values, data.toArray()))
>>> {
>>> System.out.println(
>>> "setDelimiterParsingDisabled(**true): Data not equal!");
>>> }
>>> }
>>>
>>> }
>>>
>>>
>>> Best regards.
>>>
>>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: user-unsubscribe@commons.**apache.org<[hidden email]>
>> For additional commands, e-mail: [hidden email]
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: user-unsubscribe@commons.**apache.org<[hidden email]>
> For additional commands, e-mail: [hidden email]
>
>