commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [configuration] Problem with XMLConfiguration.setProperty(String, Object) and setDelimiterParsingDisabled
Date Sat, 21 Apr 2012 23:03:19 GMT

After reading the topic "List handling" in the page "Basic Features" (,
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 ("",
"ConfDelimiterEnabled.xml" and "ConfDelimiterDisabled.xml"), all in the
same directory.

Contents of :

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
  private static final String CONF_DELIMITER_ENABLED_XML =

  // Configuration file that will have the setDelimiterParsingDisabled as
  private static final String CONF_DELIMITER_DISABLED_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

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

    XMLConfiguration confDelimiterEnabledRead = new
    String[] values =

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

    // Now using setDelimiterParsingDisabled as true.

    XMLConfiguration confDelimiterDisabledWrite = new XMLConfiguration();

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

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

    XMLConfiguration confDelimiterDisabledRead = new XMLConfiguration();

    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


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

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

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

Best regards.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message