Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-254

Wrong creation of XMLFileConfigurationDelegate in XMLConfiguration.clone()

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: 1.4
    • Component/s: None
    • Labels:
      None
    • Environment:

      Java 1.4.2, Windows XP, Shale

      Description

      The clone() operation on a XMLConfiguration does not work correctly due to the following problem:

      private class XMLFileConfigurationDelegate extends FileConfigurationDelegate
      {
      public void load(InputStream in) throws ConfigurationException

      { XMLConfiguration.this.load(in); }

      }

      Obviously the delegate references the XMLConfiguration instance it is created in. Thus when calling

      public Object clone()
      {
      XMLConfiguration copy = (XMLConfiguration) super.clone();

      // clear document related properties
      copy.document = null;

      copy.setDelegate(createDelegate());

      // clear all references in the nodes, too
      copy.getRoot().visit(new NodeVisitor()
      {
      public void visitBeforeChildren(Node node, ConfigurationKey key)

      { node.setReference(null); }

      }, null);

      return copy;
      }

      the delegate still references the original XMLConfiguration, thus will save the content of the original one
      to file instead of the clone as expected! Changing the code like this

      copy.setDelegate(copy.createDelegate());

      solves the problem! Now the cloned XMLConfiguration with all its applied changes can be saved!

        Attachments

          Activity

            People

            • Assignee:
              oheger Oliver Heger
              Reporter:
              surfer3003 Carsten Kaiser
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: