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

Incorrect super class for script containing an anonymous inner class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.0, 1.7.1, 1.7.2
    • 1.7.3, 1.8-beta-1
    • None
    • None

    Description

      When a script contains an anonymous inner class, then the compiler seems to ignore the scriptBaseClass property of CompilerConfiguration. Here's a test case which (hopefully) demonstrates this problem. The test case fails on the last assert statement.

      class ScriptTest {
          @Test
          public void scriptWithAnonymousInnerClass() {
              def configuration = new CompilerConfiguration()
              configuration.scriptBaseClass = TestScript.name
              def classLoader = new GroovyClassLoader(getClass().classLoader, configuration)
      
              // This works
              def scriptClass = classLoader.parseClass('''
                  def r = new TestRunnable()
                  class TestRunnable implements Runnable {
                      public void run() {}
                  }
      ''')
              assert TestScript.isAssignableFrom(scriptClass)
      
              // This does not work
              scriptClass = classLoader.parseClass('''
                  def r = new Runnable() {
                      public void run() { }
                  }
      ''')
              assert Script.isAssignableFrom(scriptClass)
              assert TestScript.isAssignableFrom(scriptClass) // <-- fails here    
          }
      }
      
      abstract class TestScript extends Script {
      
      }
      

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            adammurdoch Adam Murdoch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: