For https://issues.apache.org/jira/browse/OFBIZ-4882 I stumbled upon this with
OOTB setting for ScriptUtil
---- exception report ----------------------------------------------------------
Error running script at location [component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy]:
javax.script.ScriptException: java.lang.ClassCastException: org.ofbiz.base.util.UtilMi
sc$SimpleMap cannot be cast to java.lang.String
Exception: javax.script.ScriptException
Message: java.lang.ClassCastException: org.ofbiz.base.util.UtilMisc$SimpleMap
cannot be cast to java.lang.String
---- cause ---------------------------------------------------------------------
Exception: java.lang.ClassCastException
Message: org.ofbiz.base.util.UtilMisc$SimpleMap cannot be cast to
java.lang.String
---- stack trace ---------------------------------------------------------------
java.lang.ClassCastException: org.ofbiz.base.util.UtilMisc$SimpleMap cannot be
cast to java.lang.String
org.ofbiz.base.util.UtilMisc.toMap(UtilMisc.java:202)
org.ofbiz.entity.GenericDelegator.findByAnd(GenericDelegator.java:1692)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189)
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
Script12.run(Script12.groovy:137)
org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320)
org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:41)
org.ofbiz.base.util.ScriptUtil.executeScript(ScriptUtil.java:298)
I then used the trick to rather use the old GroovyUtil.runScriptAtLocation()
And got this
---- runtime exception report --------------------------------------------------
Error running script at location [component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy]:
java.lang.ClassCastException: org.ofbiz.base.util.UtilMisc$SimpleMap cannot be cast to
java.lang.String
Exception: java.lang.ClassCastException
Message: org.ofbiz.base.util.UtilMisc$SimpleMap cannot be cast to
java.lang.String
---- stack trace ---------------------------------------------------------------
java.lang.ClassCastException: org.ofbiz.base.util.UtilMisc$SimpleMap cannot be
cast to java.lang.String
org.ofbiz.base.util.UtilMisc.toMap(UtilMisc.java:202)
org.ofbiz.entity.GenericDelegator.findByAnd(GenericDelegator.java:1692)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189)
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
ProductSummary.run(ProductSummary.groovy:137)
I think you see the difference when it comes to debug errors in script between
Script12.run(Script12.groovy:137)
and
ProductSummary.run(ProductSummary.groovy:137)
Of course ProductSummary.groovy name showed also in the 1st stack trace, but
not the line number.
I wonder if OOTB we should not rather use GroovyUtil.runScriptAtLocation(). In term ofdebugging executeScript() is really hard to
follow. If someone wants to implment it's own version (ie not using Groovy) then s/he could still use executeScript()
Opinions?
Jacques