Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5321

GroovyScriptEngine getResourceConnection treats resourceName argument as URI path spec

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8.4, 1.8.6
    • 1.8.8, 2.0.2
    • GroovyScriptEngine
    • None

    Description

      If a script name that begins with a leading "/" is passed to GroovyScriptEngie.run, then getResourceConnection may fail. The resulting output message will indicate some invalid path that (intuitively) seems like it should not have been constructed by groovy. (This makes it extremely difficult to debug some issues like dynamic script names).

      I am currently running embedded groovy running in java application. Problem observed when groovy scripts (.groovy) are stored within a jar file with the application, but the issue is probably not be limited to this case.

      Example roots provided to groovy:
      "jar:file:/home/user/blah.jar!/org/someFolder" (which actually contains groovy scripts)
      "jar:file:/home/user/blah.jar!/org/someOtherFolder" (which also contains groovy scripts)

      If I incorectly pass "/coolscript.groovy" to GroovyScriptEngine.run instead of "coolscript.groovy" then I will receive an exception to the effect:
      "Cannot open URL: file:/home/user/blah.jar!/coolscript.groovy"

      The fix (for user application) is to, of course, remove the leading "/". The hope is that groovy can indicate that it is not a well formed name for a script, and throw some more meaningful exception. The alternative of continuing to use the name when it is not well formed (as though it was a path), leaves the possibility of obscure bugs.

      This is caused by the constructor for URL used in GroovyScriptEngine.getResourceConnection as described in the following javadoc:
      http://docs.oracle.com/javase/6/docs/api/java/net/URL.html#URL(java.net.URL, java.lang.String)

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            denvercoder9 Rob
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: