From 59b78a17699646b273176b6cc6115620cd2e74a1 Mon Sep 17 00:00:00 2001
From: Henry Robinson <henry@cloudera.com>
Date: Wed, 22 Jul 2009 14:49:12 +0100
Subject: [PATCH] HADOOP-6269. Fix missing synchronization around Configuration.defaultResources

---
 src/core/org/apache/hadoop/conf/Configuration.java |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/core/org/apache/hadoop/conf/Configuration.java b/src/core/org/apache/hadoop/conf/Configuration.java
index d234ff7..34dfe1f 100644
--- a/src/core/org/apache/hadoop/conf/Configuration.java
+++ b/src/core/org/apache/hadoop/conf/Configuration.java
@@ -1051,10 +1051,12 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
                              ArrayList resources,
                              boolean quiet) {
     if(loadDefaults) {
-      for (String resource : defaultResources) {
-        loadResource(properties, resource, quiet);
-      }
-    
+      // To avoid addResource causing a ConcurrentModificationException
+      synchronized(Configuration.class) {
+        for (String resource : defaultResources) {
+          loadResource(properties, resource, quiet);
+        }
+      }    
       //support the hadoop-site.xml as a deprecated case
       if(getResource("hadoop-site.xml")!=null) {
         loadResource(properties, "hadoop-site.xml", quiet);
@@ -1267,7 +1269,9 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
     StringBuffer sb = new StringBuffer();
     sb.append("Configuration: ");
     if(loadDefaults) {
-      toString(defaultResources, sb);
+      synchronized (Configuration.class) {
+        toString(defaultResources, sb);
+      }
       if(resources.size()>0) {
         sb.append(", ");
       }
-- 
1.6.0.4

