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

AbstractConfiguration does not interpolate correctly after cloning

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0
    • Component/s: Build
    • Labels:
      None

      Description

      If you clone a Configuration, does not clone the StrSubstitutor when it has been instanced, so the cloned copy has the same StrSubstituor than the original composite. If you change a property in the original compoiste it is changed in the cloned copy.

      Way to reproduce it :

      public class SampleConfiguration {
          public static void main(final String[] args) {
              final String sentence = "SELECT * FORM TABLE WHERE YEAR=${year} and QUARTER=${quarter}";
              final CompositeConfiguration cp = new CompositeConfiguration();
              cp.addProperty("year", "2000");
              cp.addProperty("quarter", "2");
      
              final AbstractConfiguration clonedConfig = (AbstractConfiguration) ConfigurationUtils.cloneConfiguration(cp);
      
              cp.setProperty("year", "2001");
              clonedConfig.setProperty("year", "2002");
      
              System.out.println("Original sentence " + PropertyConverter.interpolate(sentence, cp));
              System.out.println("Cloned sentence " + PropertyConverter.interpolate(sentence, clonedConfig));
      
              final AbstractConfiguration clonedConfig2 = (AbstractConfiguration) ConfigurationUtils.cloneConfiguration(cp);
      
              cp.setProperty("year", "2003");
              clonedConfig2.setProperty("year", "2004");
      
              System.out.println("Original sentence " + PropertyConverter.interpolate(sentence, cp));
              System.out.println("Cloned (after interpolate with same strSubstitutor )sentence "
                      + PropertyConverter.interpolate(sentence, clonedConfig2));
          }
      }  
      

      The solution can be to make in the following ways:
      Make the clone of the strSubstitutor in the AbstractConfigutration class.
      Create a clone method inside the StrSubtitutor and invoke it from the AbstractConfiguration class.
      Set null the strSubstituror when the clone method is invoked in the Abstract Configuration class. The next invocation to interpolate methos instances the strSubstitutor.

        Attachments

          Activity

            People

            • Assignee:
              oheger Oliver Heger
              Reporter:
              diego7427 Juan Diego Gago Perez
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified