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

GroovyClassloader can not reload modified script

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.8.1
    • Fix Version/s: None
    • Component/s: GroovyScriptEngine
    • Labels:
      None
    • Environment:
      groovy 1.8.1

      Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
      Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

      Description

      I found GroovyClassloader can not reload modified script.
      I am using following code:

      final CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
      compilerConfiguration.setRecompileGroovySource(true);
      cl = new GroovyClassLoader(Thread.currentThread().getContextClassLoader (), compilerConfiguration);
      cl.loadClass(applicationClassName, true, false);

      and I study the GroovyClassloader source code,and I found following code:

      Class cls = getClassCacheEntry(name);
      .....
      Class parentClassLoaderClass = super.loadClass(name, resolve);
      // always return if the parent loader was successful
      if (cls != parentClassLoaderClass) return parentClassLoaderClass;

      and I found super.loadClass always return old parsed Class instance.

      another testcase:

      GroovyScriptEngine engine = new GroovyScriptEngine(root,Thread.currentThread().getContextClassLoader());
      engine.loadScriptByName(scriptName);

      If I modified the script soruce,and I found using

      Class.forName("myClassName", true, engine.getGroovyClassLoader());

      and

      engine.getGroovyClassLoader().loadClass("myClassName")

      will return different Class instance.

        Attachments

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              ljw79618 L.J.W
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: