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

Unable to new arbitary script name for in BSFManager#exec()

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.0-beta-4
    • None

    Description

      When intergrating groovy with ant's script task I found that I needed
      to change the name of the script to make it a valid java class name.
      Attaching a cvs patch to the BsfTest to show the problem - output is
      Testcase: testBracketName took 0.023 sec
      Caused an ERROR
      Illegal class name "Test1<groovy>"
      java.lang.ClassFormatError: Illegal class name "Test1<groovy>"
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:604)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:448)
      at groovy.lang.GroovyClassLoader.access$200(GroovyClassLoader.java:60)
      at groovy.lang.GroovyClassLoader$ClassCollector.onClassNode(GroovyClassLoader.java:175)
      at groovy.lang.GroovyClassLoader$ClassCollector.onClass(GroovyClassLoader.java:185)
      at org.codehaus.groovy.classgen.CompilerFacade.generateClass(CompilerFacade.java:124)
      at org.codehaus.groovy.classgen.CompilerFacade.parseClass(CompilerFacade.java:151)
      at org.codehaus.groovy.classgen.CompilerFacade.parseClass(CompilerFacade.java:84)
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:140)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:255)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:217)
      at org.codehaus.groovy.bsf.GroovyEngine.exec(GroovyEngine.java:132)
      at org.apache.bsf.BSFManager$6.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.apache.bsf.BSFManager.exec(Unknown Source)
      at org.codehaus.groovy.bsf.BSFTest.testBracketName(BSFTest.java:81)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      Attachments

        1. g2.diff
          0.9 kB
          Peter Reilly
        2. GroovyEngine.diff
          2 kB
          Peter Reilly
        3. GroovyEngine.diff
          1 kB
          Peter Reilly

        Activity

          peter.reilly@corvil.com Peter Reilly added a comment -

          Patch to BSFTest showing the problem

          peter.reilly@corvil.com Peter Reilly added a comment - Patch to BSFTest showing the problem
          peter.reilly@corvil.com Peter Reilly added a comment -

          Added a patch to change the name of the script from
          the user input to "script" + System.currentTimeMillis() + ".groovy".
          This is of course a temporary fix.
          The root problem is that the script name is used in
          GroovyClassLoader.loadClass() as the name of the class corresponding
          to the script contents - and hence has to be a valid class name

          peter.reilly@corvil.com Peter Reilly added a comment - Added a patch to change the name of the script from the user input to "script" + System.currentTimeMillis() + ".groovy". This is of course a temporary fix. The root problem is that the script name is used in GroovyClassLoader.loadClass() as the name of the class corresponding to the script contents - and hence has to be a valid class name

          Just curiosity, why do you call it Test1<groovy> which is an illegal class name ? Isn't it logical that it fails ? Why don't you put a valid name ?
          Could you put also an excerpt of your script and the ant build file ?

          guillaume Guillaume Sauthier added a comment - Just curiosity, why do you call it Test1<groovy> which is an illegal class name ? Isn't it logical that it fails ? Why don't you put a valid name ? Could you put also an excerpt of your script and the ant build file ?
          peter.reilly@corvil.com Peter Reilly added a comment -

          Different method to fix the problem.
          If the source name is a valid java classname, then the name
          is not changed, otherwise the invalid parts of the name are
          set to "_".
          This means that current uses of bsf with groovy will not be
          affected

          peter.reilly@corvil.com Peter Reilly added a comment - Different method to fix the problem. If the source name is a valid java classname, then the name is not changed, otherwise the invalid parts of the name are set to "_". This means that current uses of bsf with groovy will not be affected
          peter.reilly@corvil.com Peter Reilly added a comment -

          Attachment number #1 is the unit test and Attachment number #2
          is the patch for GroovyEngine. Attachment number #3 is the old
          patch - do not use this one.

          peter.reilly@corvil.com Peter Reilly added a comment - Attachment number #1 is the unit test and Attachment number #2 is the patch for GroovyEngine. Attachment number #3 is the old patch - do not use this one.
          jstrachan James Strachan added a comment -

          Humblest appologies for this taking so long - many thanks for the test case and patch - applied with pleasure

          jstrachan James Strachan added a comment - Humblest appologies for this taking so long - many thanks for the test case and patch - applied with pleasure

          People

            Unassigned Unassigned
            peter.reilly@corvil.com Peter Reilly
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: