groovy

java.lang.ClassFormatError running groovy script from shell (bash)

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.1-rc-1
  • Fix Version/s: 1.5.2, 1.6-rc-2
  • Component/s: None
  • Labels:
    None
  • Environment:
    % uname -a
    Linux darwin.triactive.com 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux
  • Number of attachments :
    0

Description

Tried to run a very simple (print "helloWorld") script. Runs fine using groovy compiler, groovysh, but throws exception when trying to run as standalone script.
Script, exception, compiler output, script output, env and groovysh output below:

% cat helloWorld
#!/usr/bin/env groovy
print "helloWorld"

% ./helloWorld
Exception in thread "main" java.lang.ClassFormatError: (Illegal Class name "")
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at groovy.lang.GroovyClassLoader.access$100(GroovyClassLoader.java:78)
at groovy.lang.GroovyClassLoader$ClassCollector.onClassNode(GroovyClassLoader.java:470)
at groovy.lang.GroovyClassLoader$ClassCollector.call(GroovyClassLoader.java:480)
at org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.java:674)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:932)
at org.codehaus.groovy.control.CompilationUnit.classgen(CompilationUnit.java:591)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:485)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:226)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:154)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.GroovyShell.run(GroovyShell.java:210)
at groovy.lang.GroovyShell.main(GroovyShell.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.codehaus.classworlds.Launcher.launchStandard(Launcher.java:410)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:344)
at org.codehaus.classworlds.Launcher.main(Launcher.java:461)

% groovy helloWorld
helloWorld

% env
KDE_MULTIHEAD=false
SSH_AGENT_PID=19891
HOSTNAME=darwin.triactive.com
JRUN_HOME=/dev/null
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
GTK_RC_FILES=/etc/gtk/gtkrc:/home/fran/.gtkrc:/home/fran/.gtkrc-kde
CVSROOT=:pserver:fran@cvs:/usr/local/cvs
GS_LIB=/home/fran/.kde/share/fonts
OLDPWD=/home/fran/dev/groovy
QTDIR=/usr/lib/qt-3.1
JBOSS_HOME=/usr/local/jboss
USER=fran
LD_LIBRARY_PATH=/usr/local/lib
LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:.cmd=00;32:.exe=00;32:.com=00;32:.btm=00;32:.bat=00;32:.sh=00;32:.csh=00;32:.tar=00;31:.tgz=00;31:.arj=00;31:.taz=00;31:.lzh=00;31:.zip=00;31:.z=00;31:.Z=00;31:.gz=00;31:.bz2=00;31:.bz=00;31:.tz=00;31:.rpm=00;31:.cpio=00;31:.jpg=00;35:.gif=00;35:.bmp=00;35:.xbm=00;35:.xpm=00;35:.png=00;35:.tif=00;35:
SSH_AUTH_SOCK=/tmp/ssh-XXwRPpdo/agent.19848
SESSION_MANAGER=local/darwin.triactive.com:/tmp/.ICE-unix/19960
KONSOLE_DCOP=DCOPRef(konsole-19982,konsole)
MAVEN_HOME=/usr/local/src/maven-1.0-rc4
PATH=/home/fran/bin:/home/fran/dev/ant/bin:/usr/local/epsilon11/bin:/usr/local/groovy/bin:/home/fran/bin:/home/fran/dev/ant/bin:/usr/local/epsilon11/bin:/usr/local/groovy/bin:/usr/java/bin:/usr/local/resin/bin:/usr/local/jboss/bin:/usr/local/apache/bin:/usr/local/epsilon11/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/fran/bin:/usr/local/src/maven-1.0-rc4/bin:.
MAIL=/var/spool/mail/fran
KONSOLE_DCOP_SESSION=DCOPRef(konsole-19982,session-4)
PWD=/home/fran
INPUTRC=/etc/inputrc
XMODIFIERS=@im=none
JAVA_HOME=/usr/java
LANG=en_US.UTF-8
GDMSESSION=KDE
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SHLVL=3
HOME=/home/fran
LOGNAME=fran
GROOVY_HOME=/usr/local/groovy
RESIN_HOME=/usr/local/resin
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
LESSOPEN=|/usr/bin/lesspipe.sh %s
DISPLAY=:0
APACHE_HOME=/usr/local/apache
DEV=/home/fran/dev/
G_BROKEN_FILENAMES=1
COLORTERM=
XAUTHORITY=/home/fran/.Xauthority
_=/usr/bin/env

% groovysh
Lets get Groovy!
================
Version: 1.0-beta-6-SNAPSHOT JVM: 1.4.2_04-b05
Type 'exit' to terminate the shell
Type 'help' for command help

1> print "helloWorld"
2> go
helloWorld
1> quit
%

Issue Links

Activity

Hide
John Stump added a comment -

The problem is that your file has no extension on it. Even adding a "." on the end of the filename would work. Somewhere in the code it expects the filename to have an extension, and if it doesn't, it won't handle this condition. I tried to find it, but failed as it went deep into the bowels of the compiler. Someone else want to take a crack at it?

This is yet another example documented on the web site that DOES NOT WORK!!

Show
John Stump added a comment - The problem is that your file has no extension on it. Even adding a "." on the end of the filename would work. Somewhere in the code it expects the filename to have an extension, and if it doesn't, it won't handle this condition. I tried to find it, but failed as it went deep into the bowels of the compiler. Someone else want to take a crack at it? This is yet another example documented on the web site that DOES NOT WORK!!
Hide
Guillaume Laforge added a comment -

There's a mandatory extension for groovy source files.

Show
Guillaume Laforge added a comment - There's a mandatory extension for groovy source files.
Hide
David Dahl added a comment -

This is indeed a bug and the issue should not be closed.
The problem is a leading "./" when the executed script is in the current working directory.

Consider the "Hello World" example at http://groovy.codehaus.org/Running.

> #!/usr/bin/env groovy
> println("Hello world")
> for (a in this.args) { > println("Argument: " + a) > }

When executed as "groovy helloWorld", everything is fine.

When executed as "groovy ./helloWorld", the exception occurs:

Exception in thread "main" java.lang.ClassFormatError: Illegal class name "" in class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at groovy.lang.GroovyClassLoader.access$100(GroovyClassLoader.java:70)
at groovy.lang.GroovyClassLoader$ClassCollector.onClassNode(GroovyClassLoader.java:478)
at groovy.lang.GroovyClassLoader$ClassCollector.call(GroovyClassLoader.java:488)
at org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.java:587)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:822)
at org.codehaus.groovy.control.CompilationUnit.classgen(CompilationUnit.java:525)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:432)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:234)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:203)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:153)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:221)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.GroovyShell.run(GroovyShell.java:219)
at groovy.lang.GroovyShell.run(GroovyShell.java:163)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:366)
at groovy.ui.GroovyMain.run(GroovyMain.java:232)
at groovy.ui.GroovyMain.process(GroovyMain.java:218)
at groovy.ui.GroovyMain.main(GroovyMain.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchStandard(Launcher.java:410)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:344)
at org.codehaus.classworlds.Launcher.main(Launcher.java:461)

Show
David Dahl added a comment - This is indeed a bug and the issue should not be closed. The problem is a leading "./" when the executed script is in the current working directory. Consider the "Hello World" example at http://groovy.codehaus.org/Running. > #!/usr/bin/env groovy > println("Hello world") > for (a in this.args) { > println("Argument: " + a) > } When executed as "groovy helloWorld", everything is fine. When executed as "groovy ./helloWorld", the exception occurs: Exception in thread "main" java.lang.ClassFormatError: Illegal class name "" in class file at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) at groovy.lang.GroovyClassLoader.access$100(GroovyClassLoader.java:70) at groovy.lang.GroovyClassLoader$ClassCollector.onClassNode(GroovyClassLoader.java:478) at groovy.lang.GroovyClassLoader$ClassCollector.call(GroovyClassLoader.java:488) at org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.java:587) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:822) at org.codehaus.groovy.control.CompilationUnit.classgen(CompilationUnit.java:525) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:432) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:234) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:203) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:153) at groovy.lang.GroovyShell$2.run(GroovyShell.java:221) at java.security.AccessController.doPrivileged(Native Method) at groovy.lang.GroovyShell.run(GroovyShell.java:219) at groovy.lang.GroovyShell.run(GroovyShell.java:163) at groovy.ui.GroovyMain.processOnce(GroovyMain.java:366) at groovy.ui.GroovyMain.run(GroovyMain.java:232) at groovy.ui.GroovyMain.process(GroovyMain.java:218) at groovy.ui.GroovyMain.main(GroovyMain.java:122) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.codehaus.classworlds.Launcher.launchStandard(Launcher.java:410) at org.codehaus.classworlds.Launcher.launch(Launcher.java:344) at org.codehaus.classworlds.Launcher.main(Launcher.java:461)
Hide
Russel Winder added a comment -

I think it is not reasonable to assume that a file name has an extension in order to be used with a relative path.

Show
Russel Winder added a comment - I think it is not reasonable to assume that a file name has an extension in order to be used with a relative path.
Hide
Russel Winder added a comment -

Updating this issue to be the marker for a problem that affects relative path usage but not absolute path usage for executing scripts.

Show
Russel Winder added a comment - Updating this issue to be the marker for a problem that affects relative path usage but not absolute path usage for executing scripts.
Hide
Russel Winder added a comment -

Kicking this bug since it is a bug and it will affect all non-Windows users who write scripts – since not having extensions on a file name is standard procedure.

If we want to close this one and reopen GROOVY-2081 instead as the marker for this problem, then that is fine.

Show
Russel Winder added a comment - Kicking this bug since it is a bug and it will affect all non-Windows users who write scripts – since not having extensions on a file name is standard procedure. If we want to close this one and reopen GROOVY-2081 instead as the marker for this problem, then that is fine.
Hide
Paul King added a comment -

I think this issue is solved but I don't have sufficient environments/platforms to test it on to be doubly sure. It appears that the need for an extension was removed some time ago but that in some unix environments there was a space being added to the script filename during command line parsing. I plan to mark this issue as closed in the coming days if I receive no further feedback.

Show
Paul King added a comment - I think this issue is solved but I don't have sufficient environments/platforms to test it on to be doubly sure. It appears that the need for an extension was removed some time ago but that in some unix environments there was a space being added to the script filename during command line parsing. I plan to mark this issue as closed in the coming days if I receive no further feedback.
Hide
Phil Walker added a comment -

This appears to be fixed in 1.5.1, based on a quick check ...

Show
Phil Walker added a comment - This appears to be fixed in 1.5.1, based on a quick check ...
Hide
Russel Winder added a comment -

The script:

#! /usr/bin/env groovy
// -*- mode:groovy encoding:UTF-8 -*-

println ( 'Hello World' )

stored in a file GROOVY_569, without an extension and with the execute bit set, certainly executes fine on Ubuntu with Groovy Subversion HEAD as at 2008-01-18 using the commands:

GROOVY_569
./GROOVY_569
/home/users/russel/Progs/OddsByLanguage/Groovy/GROOVY_569

There is a sever problem with the command line:

../Groovy/GROOVY_569

but this is the bug reported as GROOVY-2081 so I have reopened that bug. It seems it is right to have this bug marked as fixed and closed.

Show
Russel Winder added a comment - The script:
#! /usr/bin/env groovy
// -*- mode:groovy encoding:UTF-8 -*-

println ( 'Hello World' )
stored in a file GROOVY_569, without an extension and with the execute bit set, certainly executes fine on Ubuntu with Groovy Subversion HEAD as at 2008-01-18 using the commands:
GROOVY_569
./GROOVY_569
/home/users/russel/Progs/OddsByLanguage/Groovy/GROOVY_569
There is a sever problem with the command line:
../Groovy/GROOVY_569
but this is the bug reported as GROOVY-2081 so I have reopened that bug. It seems it is right to have this bug marked as fixed and closed.

People

Vote (2)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: