Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1055

StrSubstitutor.replaceSystemProperties does not work consistently

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.3.2
    • 3.4
    • lang.text.*
    • None
    • Windows 7, Java 7

    Description

      StrSubsitutor caches a references to SystemProperties statically on first class references. This does not work properly with System.setProperties(). For example the following code:

      package test.utilities;
      
      import java.util.Properties;
      
      import org.apache.commons.lang.text.StrSubstitutor;
      
      public class TestStrSubstitutor {
      
          public static void main(String[] args) {
              System.out.println(StrSubstitutor.replaceSystemProperties("os.name=${os.name}"));
              Properties testProps = new Properties();
              testProps.put("test_key",  "test_value");
              testProps.putAll(System.getProperties());
              System.setProperties(testProps);
              System.out.println(StrSubstitutor.replace("test_key=${test_key}", System.getProperties()));
              System.out.println(StrSubstitutor.replaceSystemProperties("test_key=${test_key}"));
          }
      
      }
      

      produces the following output:

      os.name=Windows 7
      test_key=test_value
      test_key=${test_key}
      

      The code linked here shows the static caching of the System Properties reference: http://commons.apache.org/proper/commons-lang/apidocs/src-html/org/apache/commons/lang3/text/StrLookup.html

      Attachments

        Activity

          People

            britter Benedikt Ritter
            philci52 Phil Dicke
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: