Menu

Groovy class name spec for XmlAction

2012-01-13
2012-09-09
  • Vasanth Kamatgi

    Vasanth Kamatgi - 2012-01-13

    XmlAction generates groovy class using the passed-in location argument.
    XmlAction instance for each screen is initialized using the screen's @location
    + ".actions". @location can be any valid string including hyphens, dots or any
    other characters. Using the same value for class generation by Groovy could be
    error prone. I encountered this scenario when I had a screen with a hyphen in
    it's location.

    --- 30900    [ndlerThread[#4]] ERROR         org.moqui.impl.actions.XmlAction 
     Error running groovy script [
    1 : import org.moqui.impl.StupidUtilities
    2 : // these are in the context by default: ExecutionContext ec, Map<String, Object> context, Map<String, Object> result
    3 : ec.resource.runScriptInCurrentContext("component://mycomponent/script/com/xyz/mycomponent/Test.groovy", null)
    4 :     // begin inline script
    5 :     
    6 :     // end inline script
    
    ]: java.lang.ClassFormatError: Illegal class name "start-test/xml/screen$run" in class file start-test/xml/screen$run
    --- 30905    [ndlerThread[#4]] ERROR   org.moqui.impl.screen.ScreenRenderImpl 
     Error rendering screen [component://mycomponent/screen/mycomponent/start-test.xml]
    java.lang.ClassFormatError: Illegal class name "start-test/xml/screen$run" in class file start-test/xml/screen$run
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.define(ClassLoaderForClassArtifacts.java:42)
        at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts$1.run(ClassLoaderForClassArtifacts.java:86)
        at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts$1.run(ClassLoaderForClassArtifacts.java:84)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.defineClassAndGetConstructor(ClassLoaderForClassArtifacts.java:84)
        at org.codehaus.groovy.runtime.callsite.CallSiteGenerator.compilePogoMethod(CallSiteGenerator.java:217)
        at org.codehaus.groovy.reflection.CachedMethod.createPogoMetaMethodSite(CachedMethod.java:228)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.createCachedMethodSite(PogoMetaMethodSite.java:207)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.createPogoMetaMethodSite(PogoMetaMethodSite.java:183)
        at groovy.lang.MetaClassImpl.createPogoCallSite(MetaClassImpl.java:3002)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPogoSite(CallSiteArray.java:134)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:148)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
        at mycomponent.xml.screen$run.call(Unknown Source)
        at org.moqui.impl.actions.XmlAction.run(XmlAction.groovy:91)
        more errors...
    

    Will there be any downside if we sanitize the location argument received in
    the constructor of XmlAction before sending it to
    GroovyClassLoader(XmlAction.groovy:37, XmlAction.groovy:54). Or may be use the
    other variant, i.e., GroovyClassLoader.parseClass(String text) so that we do
    not need to worry about the Class Name at all. Do you foresee any impact in
    other areas of moqui due to this change?

     
  • David E. Jones

    David E. Jones - 2012-01-13

    The solution used elsewhere (including screens, etc) is to clean up the name
    before passing it along. It looks like this issue was present in 2 places in
    XmlAction.groovy, and 1 place in GroovyScriptRunner.groovy.

    This should be fixed in commit b90193b.

     

Log in to post a comment.