From a667b2468c0011123fedaa0dc01555b1dea8db0c Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Mon, 9 Mar 2009 10:37:00 +0000 Subject: [PATCH] Fix for ALFCOM-1666 - Null pointer when calling ScriptNode in Java (for workflow) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13499 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/repo/jscript/ValueConverter.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/source/java/org/alfresco/repo/jscript/ValueConverter.java b/source/java/org/alfresco/repo/jscript/ValueConverter.java index ebd13e0042..4e23056ee8 100644 --- a/source/java/org/alfresco/repo/jscript/ValueConverter.java +++ b/source/java/org/alfresco/repo/jscript/ValueConverter.java @@ -43,7 +43,6 @@ import org.mozilla.javascript.IdScriptableObject; import org.mozilla.javascript.NativeArray; import org.mozilla.javascript.ScriptRuntime; import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.Wrapper; @@ -96,9 +95,18 @@ public class ValueConverter // call the "Date" constructor on the root scope object - passing in the millisecond // value from the Java date - this will construct a JavaScript Date with the same value Date date = (Date)value; - Object val = ScriptRuntime.newObject( + + try + { + Context.enter(); + Object val = ScriptRuntime.newObject( Context.getCurrentContext(), scope, TYPE_DATE, new Object[] {date.getTime()}); - value = (Serializable)val; + value = (Serializable)val; + } + finally + { + Context.exit(); + } } else if (value instanceof Collection) { @@ -110,8 +118,16 @@ public class ValueConverter { array[index++] = convertValueForScript(services, scope, qname, obj); } - // convert array to a native JavaScript Array - value = (Serializable)Context.getCurrentContext().newArray(scope, array); + try + { + Context.enter(); + // convert array to a native JavaScript Array + value = (Serializable)Context.getCurrentContext().newArray(scope, array); + } + finally + { + Context.exit(); + } } // simple numbers and strings are wrapped automatically by Rhino