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

embedded: when using alternative classloader code parsing succeeds but evaluation fails

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-7
    • 1.0-JSR-3
    • None
    • None
    • Win32, sun jdk 1.4.2_05, eclipse 2.1.2 runtime workbench

    Description

      The situation is:

      0) using embedded groovy in eclipse plugin as service for projects. each project has it's own classloader different from plugin classloader (like "A" below)

      1) class loader A knows about class pkg.X
      2) creating GS = new GroovyShell(A)
      3) creating Script instance by means of
      code = "import pkg.X; ..."; // pkg.X is reffered directly
      S1=GS.parse(code); - parsing succeeds

      parsed script instance is required for caching to get rid of parsing overhead on further script invocations

      4) now running S1.run() fails with NoClassDefFoundError:

      java.lang.NoClassDefFoundError: pkg.X
      at Script1.class$(Script1.groovy)
      at Script1.run(Script1.groovy:1)
      ...

      Setting thread context classloader to A durin S1.run() does not affect

      Seems it uses default MetaClassRegistry.loader - GroovyClassLoader(getClass().getClassLoader())

      while getClass().getClassLoader() apparently knows nothing about pkg.X

      — Possible Issues
      1) It may be possible to keep classloader associated with particular script instance

      2) It may be alternative issue to include classloader info into Binding like it's done in OGNL:

      binding.setClassLoader(a)
      S1.setBinding(binding)
      S1.run()

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            [fog] Andrey Alexeyenko
            Votes:
            8 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: