Kaynağa Gözat

HADOOP-6871. When the value of a configuration key is set to its unresolved form, it causes an IllegalStateException in Configuration.get() stating that substitution depth is too large. Contributed by Arvind Prabhakar (harsh)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1342626 13f79535-47bb-0310-9956-ffa450edef68
Harsh J 13 yıl önce
ebeveyn
işleme
4709160d75

+ 5 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -153,6 +153,11 @@ Trunk (unreleased changes)
     HADOOP-8413. test-patch.sh gives out the wrong links for
     newPatchFindbugsWarnings (Colin Patrick McCabe via bobby)
 
+    HADOOP-6871. When the value of a configuration key is set to its
+    unresolved form, it causes the IllegalStateException in
+    Configuration.get() stating that substitution depth is too large.
+    (Arvind Prabhakar via harsh)
+
   OPTIMIZATIONS
 
     HADOOP-7761. Improve the performance of raw comparisons. (todd)

+ 6 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java

@@ -617,7 +617,13 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
     }
     Matcher match = varPat.matcher("");
     String eval = expr;
+    Set<String> evalSet = new HashSet<String>();
     for(int s=0; s<MAX_SUBST; s++) {
+      if (evalSet.contains(eval)) {
+        // Cyclic resolution pattern detected. Return current expression.
+        return eval;
+      }
+      evalSet.add(eval);
       match.reset(eval);
       if (!match.find()) {
         return eval;

+ 9 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java

@@ -999,6 +999,15 @@ public class TestConfiguration extends TestCase {
         "Not returning expected number of classes. Number of returned classes ="
             + classes.length, 0, classes.length);
   }
+
+  public void testInvalidSubstitutation() {
+    String key = "test.random.key";
+    String keyExpression = "${" + key + "}";
+    Configuration configuration = new Configuration();
+    configuration.set(key, keyExpression);
+    String value = configuration.get(key);
+    assertTrue("Unexpected value " + value, value.equals(keyExpression));
+  }
   
   public static void main(String[] argv) throws Exception {
     junit.textui.TestRunner.main(new String[]{