Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration

XMLPropertyListConfiguration parses Map members containing commas when instructed not to



    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.9
    • Fix Version/s: None
    • Component/s: Format
    • Labels:


      XMLPropertyListConfiguration does not properly handle String properties containing commas when added to the plist as part of a Map.

      The following code demonstrates the problem.

      Sample Code
      public class FooBar extends Object {
         public static final void main(String[] args) throws Exception {
            XMLPropertyListConfiguration config =new XMLPropertyListConfiguration();
            config.setProperty("one", "this, that");
            Map<String, String> map =new HashMap<String, String>();
            map.put("two", "this, that");
            config.addProperty("foo", map);
            StringWriter strwriter =new StringWriter();

      This code produces the following plist.

      <?xml version="1.0"?>
      <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
      <plist version="1.0">
              <string>this, that</string>

      Note that "this, that" has been split into two properties, despite the list delimiter being set away from the comma default and delimiter parsing disabled.

      The problem is in XMLPropertyListConfiguration's printValue(PrintWriter, int, Object) method. This method create a MapConfiguration containing the (transformed) "foo" Map.

      Existing XMLPropertyListConfiguration code
         printValue(out, indentLevel, new MapConfiguration(map));

      The XMLPropertyListConfiguration's delimiter-related settings are never passed to the MapConfiguration, which retains the enabled and comma defaults.

      The following patch to XMLPropertyListConfiguration.java makes Commons Configuration more correct.

      XMLPropertyListConfiguration.java Patch
      <             printValue(out, indentLevel, new MapConfiguration(map));
      >             MapConfiguration mapconfig =new MapConfiguration(map);
      >             mapconfig.setDefaultListDelimiter(getDefaultListDelimiter());
      >             mapconfig.setDelimiterParsingDisabled(isDelimiterParsingDisabled());
      >             printValue(out, indentLevel, mapconfig);

      With this patch applied, the program outputs the expected plist.

      <?xml version="1.0"?>
      <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
      <plist version="1.0">
              <string>this, that</string>
                  <string>this, that</string>

      While this patch may provide correct functionality for most use cases, it is still not correct. Major structural work needs to be done to fix the problem.

      The documentation for AbstractConfiguration's setDefaultListDelimiter(char) method states, "This value will be used only when creating new configurations. Those already created will not be affected by this change". AbstractConfiguration's documentation for setListDelimiter(char) states, "Note: this change will only be effective for new parsings. If you want it to take effect for all loaded properties use the no arg constructor and call this method before setting the source."

      MapConfiguration extends AbstractConfiguration, yet does not honor the inherited contracts. That MapConfiguration does not have a no arg constructor is fair enough, though would be somewhat limiting if it did follow the contracts. That invocations of setDefaultListDelimiter() and setListDelimiter() effect previously added properties is simply wrong. Unless state is maintained for each added property (which would be a messy implementation), the parsing must not be executed within the getProperty(String) method. Instead, values must be parsed upon being added to the MapConfiguration.

      The same problem exists within XMLPropertyListConfiguration. The delegated parsing at issue in the bug report is invoked from the printValue(PrintWriter, int, Object) method, which is far too late (again, barring state-saving), to honor the contract that added properties are parsed, or not, according to the delimiter settings in place at the time each property is added.




            • Assignee:
              kend Ken
            • Votes:
              1 Vote for this issue
              3 Start watching this issue


              • Created: