You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2012/04/06 14:51:14 UTC

svn commit: r1310307 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java

Author: adrianc
Date: Fri Apr  6 12:51:14 2012
New Revision: 1310307

URL: http://svn.apache.org/viewvc?rev=1310307&view=rev
Log:
Bug fix in ScriptUtil.java - create a local copy of the calling context so script local variables are not copied to it.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java?rev=1310307&r1=1310306&r2=1310307&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java Fri Apr  6 12:51:14 2012
@@ -26,6 +26,7 @@ import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -203,14 +204,15 @@ public final class ScriptUtil {
      */
     public static ScriptContext createScriptContext(Map<String, Object> context) {
         Assert.notNull("context", context);
-        context.put(WIDGET_CONTEXT_KEY, context);
-        context.put("context", context);
+        Map<String, Object> localContext = new HashMap<String, Object>(context);
+        localContext.put(WIDGET_CONTEXT_KEY, context);
+        localContext.put("context", context);
         ScriptContext scriptContext = new SimpleScriptContext();
         ScriptHelper helper = createScriptHelper(scriptContext);
         if (helper != null) {
-            context.put(SCRIPT_HELPER_KEY, helper);
+            localContext.put(SCRIPT_HELPER_KEY, helper);
         }
-        Bindings bindings = new SimpleBindings(context);
+        Bindings bindings = new SimpleBindings(localContext);
         scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
         return scriptContext;
     }
@@ -227,14 +229,15 @@ public final class ScriptUtil {
      */
     public static ScriptContext createScriptContext(Map<String, Object> context, Set<String> protectedKeys) {
         Assert.notNull("context", context, "protectedKeys", protectedKeys);
-        context.put(WIDGET_CONTEXT_KEY, context);
-        context.put("context", context);
+        Map<String, Object> localContext = new HashMap<String, Object>(context);
+        localContext.put(WIDGET_CONTEXT_KEY, context);
+        localContext.put("context", context);
         ScriptContext scriptContext = new SimpleScriptContext();
-        Bindings bindings = new ProtectedBindings(context, Collections.unmodifiableSet(protectedKeys));
+        Bindings bindings = new ProtectedBindings(localContext, Collections.unmodifiableSet(protectedKeys));
         scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
         ScriptHelper helper = createScriptHelper(scriptContext);
         if (helper != null) {
-            context.put(SCRIPT_HELPER_KEY, helper);
+            localContext.put(SCRIPT_HELPER_KEY, helper);
         }
         return scriptContext;
     }