[FELIX-4342] Substitution is dependent on the order of the map

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1547767 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java b/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
index 66178f0..3499584 100644
--- a/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
+++ b/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
@@ -75,10 +75,11 @@
      */
     public static void performSubstitution(Map<String,String> properties, SubstitutionCallback callback)
     {
+        Map<String, String> org = new HashMap<String, String>(properties);
         for (String name : properties.keySet())
         {
             String value = properties.get(name);
-            properties.put(name, substVars(value, name, null, properties, callback));
+            properties.put(name, substVars(value, name, null, org, callback));
         }
     }
 
diff --git a/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java b/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java
index 7d687e0..8e5ebf9 100644
--- a/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java
+++ b/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java
@@ -20,6 +20,7 @@
 
 import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.LinkedHashMap;
 
 public class InterpolationHelperTest extends TestCase {
 
@@ -126,4 +127,21 @@
         assertEquals("${a}", InterpolationHelper.substVars("$\\{a\\}", "b", null, new Hashtable(), context));
     }
 
+    public void testSubstitutionOrder()
+    {
+        LinkedHashMap<String, String> map1 = new LinkedHashMap<String, String>();
+        map1.put("a", "$\\\\{var}");
+        map1.put("abc", "${ab}c");
+        map1.put("ab", "${a}b");
+        InterpolationHelper.performSubstitution(map1);
+
+        LinkedHashMap<String, String> map2 = new LinkedHashMap<String, String>();
+        map2.put("a", "$\\\\{var}");
+        map2.put("ab", "${a}b");
+        map2.put("abc", "${ab}c");
+        InterpolationHelper.performSubstitution(map2);
+
+        assertEquals(map1, map2);
+    }
+
 }
diff --git a/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java b/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
index ecef3ac..a5006ea 100644
--- a/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
+++ b/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
@@ -22,6 +22,7 @@
 import java.io.StringWriter;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 import junit.framework.TestCase;
 
@@ -121,6 +122,22 @@
         assertEquals(props1, props2);
     }
 
+    public void testConfigInterpolation() throws IOException
+    {
+        String config = "a=$\\\\\\\\{var}\n" +
+                "ab=${a}b\n" +
+                "abc=${ab}c";
+
+        java.util.Properties props1 = new java.util.Properties();
+        props1.load(new StringReader(config));
+        InterpolationHelper.performSubstitution((Map) props1);
+
+        org.apache.felix.utils.properties.Properties props2 = new org.apache.felix.utils.properties.Properties();
+        props2.load(new StringReader(config));
+
+        assertEquals(props1, props2);
+    }
+
     /**
      * <p>
      * Test getting property.