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

Add option to allow a new classloader to be used per run

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Groovy Console

    Description

      Add an option flag to Groovy Console that specifies whether a new classloader should be used upon each run of the script.

      Currently, a console window's classloader persists class loads across runs. This can cause unintended results when experimenting with meta-programming. For example, if I run this script twice from Groovy Console:

          try {
              ''.nonExistentMethod()
          } catch (e) {
              println 'Unable to call non-existent method'
          }
          String.metaClass.nonExistentMethod << { ->
              println 'It exists now!'
          }
          ''.nonExistentMethod()
          println 'Script Execution Complete'
      

      The output is:

          Unable to call non-existent method
          It exists now!
          Script Execution Complete
          It exists now!
          It exists now!
          Script Execution Complete
      

      The method added to the String's meta-class was "remembered" between successive executions due to the classloader being reused. I would rather the console would forget and allow the output be consistent for each run.

      Attachments

        Activity

          People

            Unassigned Unassigned
            bdkosher Joe Wolf
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: