groovy
  1. groovy
  2. GROOVY-3054

ClassFormatError: Illegal class name Exception when running a script from a folder with dot in its name

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.6
    • Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
    • Component/s: bytecode
    • Labels:
      None
    • Environment:
      Ubuntu 7.10
      SunOS 5.10
    • Number of attachments :
      0

      Description

      To reproduce this error just generate a folder with the name "test-7.2"
      and generate in it an easy script file named Test:

      //script file
      println 'foo'

      When you run this script the following Exception is thrown:
      Caught: java.lang.ClassFormatError: Illegal class name "test-7" in class file test-7

      If you rename the file to something with a dot extension (e.g. Test.groovy or Test.test) it works.

        Activity

        blackdrag blackdrag made changes -
        Field Original Value New Value
        Fix Version/s 1.6-rc-1 [ 14009 ]
        Fix Version/s 1.5.8 [ 14630 ]
        Hide
        Paul King added a comment -

        Doesn't appear to be a problem on Windows on trunk using the batch startup script

        Show
        Paul King added a comment - Doesn't appear to be a problem on Windows on trunk using the batch startup script
        Hide
        blackdrag blackdrag added a comment - - edited

        the environment is Ubuntu, so it is the shell scripts for linux. We source the startGroovy script using ".", maybe that is the reason.. I think there is an alternative way to do that.... on the other hand I don't see a direct relation

        Show
        blackdrag blackdrag added a comment - - edited the environment is Ubuntu, so it is the shell scripts for linux. We source the startGroovy script using ".", maybe that is the reason.. I think there is an alternative way to do that.... on the other hand I don't see a direct relation
        Hide
        Marcel Szalbach added a comment -

        Hi,

        thanks for the reply and the hint with the sourcing with the dot.
        I did some debugging and testing with the linux commands.

        Here are some points I found out:

        I changed the "groovy" script to a bash function and use the source command, to test if its a problem of sh only, but it also occurs.

        I checked the parameters given to the java command and the end of the startGroovy script. They are the same for a groovy script in an folder with dot in its name and not and for a script ending with .groovy in a dot folder (which will also work).

        I also tested this behavior on Windows Vista and the problem occurs also with groovy 1.5.6.

        Mr King could you please test it again with windows and the following settings:
        Folder name: "test-7.2"
        File name: "Test"
        It is important that the file has no file extension (check if maybe your Windows hides the extensions, because this is default setting)
        The script should not have any class definition in it, just:

        Test
        //script file
        println 'foo'
        

        From this tests I would say that the problem is not related to Linux or the start shell scripts. The Problem lies in the conversion from a classless groovy script to a java class file. I also think this problem affects Windows XP ( I did not test it, but if you wish, I can deliver test results for this too.)

        Currently the only workaround I have found is to give the file an extension(".groovy", ".script" etc.) or to define a class in the groovy file:

        Test
        class Script{
          def main( args ) {
              println 'foo'
          }
        }
        
        Show
        Marcel Szalbach added a comment - Hi, thanks for the reply and the hint with the sourcing with the dot. I did some debugging and testing with the linux commands. Here are some points I found out: I changed the "groovy" script to a bash function and use the source command, to test if its a problem of sh only, but it also occurs. I checked the parameters given to the java command and the end of the startGroovy script. They are the same for a groovy script in an folder with dot in its name and not and for a script ending with .groovy in a dot folder (which will also work). I also tested this behavior on Windows Vista and the problem occurs also with groovy 1.5.6. Mr King could you please test it again with windows and the following settings: Folder name: "test-7.2" File name: "Test" It is important that the file has no file extension (check if maybe your Windows hides the extensions, because this is default setting) The script should not have any class definition in it, just: Test //script file println 'foo' From this tests I would say that the problem is not related to Linux or the start shell scripts. The Problem lies in the conversion from a classless groovy script to a java class file. I also think this problem affects Windows XP ( I did not test it, but if you wish, I can deliver test results for this too.) Currently the only workaround I have found is to give the file an extension(".groovy", ".script" etc.) or to define a class in the groovy file: Test class Script{ def main( args ) { println 'foo' } }
        Hide
        Paul King added a comment -

        Interesting. I was using test.7 as my folder name before. I just tried these names:

        C:\temp> groovy test.7.2\Script
        Sun Nov 16 05:39:51 EST 2008
        
        C:\temp> groovy test-7-2\Script
        Sun Nov 16 05:39:57 EST 2008
        
        C:\temp> groovy test.7-2\Script
        Sun Nov 16 05:43:48 EST 2008
        
        C:\temp> groovy test-7.2\Script
        Caught: java.lang.ClassFormatError: Illegal class name "test-7" in class file test-7
        

        Then when I try groovyc instead of groovy I notice that the test.7.2 variation creates a directory test containing a class 7.class which I can run while the test-7.2 variation creates a class called test-7.class in the current directory which I can't run. I assumed that '-' was the problem in the name but it seems to have replaced that under the covers. The internal name is test_2D_7 and it appears to find it but then stops with:

        Exception in thread "main" java.lang.ClassFormatError: Field "this" in class test-7 has illegal signature "Ltest-7;"
        
        Show
        Paul King added a comment - Interesting. I was using test.7 as my folder name before. I just tried these names: C:\temp> groovy test.7.2\Script Sun Nov 16 05:39:51 EST 2008 C:\temp> groovy test-7-2\Script Sun Nov 16 05:39:57 EST 2008 C:\temp> groovy test.7-2\Script Sun Nov 16 05:43:48 EST 2008 C:\temp> groovy test-7.2\Script Caught: java.lang.ClassFormatError: Illegal class name "test-7" in class file test-7 Then when I try groovyc instead of groovy I notice that the test.7.2 variation creates a directory test containing a class 7.class which I can run while the test-7.2 variation creates a class called test-7.class in the current directory which I can't run. I assumed that '-' was the problem in the name but it seems to have replaced that under the covers. The internal name is test_2D_7 and it appears to find it but then stops with: Exception in thread "main" java.lang.ClassFormatError: Field "this" in class test-7 has illegal signature "Ltest-7;"
        Hide
        Paul King added a comment -

        OK, I have a fix for this. Will commit soon.

        Show
        Paul King added a comment - OK, I have a fix for this. Will commit soon.
        Paul King made changes -
        Assignee Paul King [ paulk ]
        Hide
        Paul King added a comment -

        fixed

        Show
        Paul King added a comment - fixed
        Paul King made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.7-beta-1 [ 14014 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Hide
        Andrew Diller added a comment -

        This is broken in Mac OSX 10.6 with Groovy Shell (1.6.4, JVM: 1.6.0_15)

        DIVWL-9KQHK92:~/work/local_src [508]$ groovy tc-info.groovy 
        Caught: java.lang.ClassFormatError: Illegal class name "groovyx/net/http/tc-info" in class file groovyx/net/http/tc-info
        
        Show
        Andrew Diller added a comment - This is broken in Mac OSX 10.6 with Groovy Shell (1.6.4, JVM: 1.6.0_15) DIVWL-9KQHK92:~/work/local_src [508]$ groovy tc-info.groovy Caught: java.lang.ClassFormatError: Illegal class name "groovyx/net/http/tc-info" in class file groovyx/net/http/tc-info

          People

          • Assignee:
            Paul King
            Reporter:
            Marcel Szalbach
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: