groovy

class resolution pb when A.groovy script calls class in B.groovy under Java 5

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.0-JSR-4
  • Fix Version/s: 1.0-JSR-6
  • Component/s: None
  • Labels:
    None
  • Environment:
    Java 5 only
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

Posted on behalf of Stefan Roock

try this (is for WinXp command shell, adapt for others)


set CLASSPATH=.
echo class Bla{ def bla(){1}} > Bla.groovy
groovy -e "assert 1==new Bla().bla()"


it works fine with JDK 1.4
with JDK 1.5 you get
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, script_from_command_line: 1: unable to resolve class Bla
@ line 1, column 11.

Activity

Hide
blackdrag blackdrag added a comment -

would be nice if someone could test this issue with cvs head at last from 03/03/2006

Show
blackdrag blackdrag added a comment - would be nice if someone could test this issue with cvs head at last from 03/03/2006
Hide
Dierk Koenig added a comment -

tested with JDK 1.5.0_05 and it works now.

Is there any way that we could have a unit test for this?

Show
Dierk Koenig added a comment - tested with JDK 1.5.0_05 and it works now. Is there any way that we could have a unit test for this?
Hide
blackdrag blackdrag added a comment -

The problem was that a file was searched in the classpath. But not the classpath you set in a variable, no it is searched from the paths stored in the GCL. But not all paths are stored there, the paths the RootLoader gets are not sotred there. And any custom path from the command line or from the configuration file is stored in the RootLoader. I now change GCL so it does use getResource to search for files, which means the RootLoader's classpath is implicitly searched too. This way the error can not happen again. If we do any test, then maybe something that sets up a RootLoader containing a groovy file and a GCL as child without any additional classpath and let the GCL load that file. This then will only work if the GCL does search with the help of RootLoader.

How about that?

Show
blackdrag blackdrag added a comment - The problem was that a file was searched in the classpath. But not the classpath you set in a variable, no it is searched from the paths stored in the GCL. But not all paths are stored there, the paths the RootLoader gets are not sotred there. And any custom path from the command line or from the configuration file is stored in the RootLoader. I now change GCL so it does use getResource to search for files, which means the RootLoader's classpath is implicitly searched too. This way the error can not happen again. If we do any test, then maybe something that sets up a RootLoader containing a groovy file and a GCL as child without any additional classpath and let the GCL load that file. This then will only work if the GCL does search with the help of RootLoader. How about that?
Hide
Dierk Koenig added a comment -

sounds perfect

Show
Dierk Koenig added a comment - sounds perfect
Hide
Arjumand Bonhomme added a comment -

Would this bug also apply to ANY classes that are specified in CLASSPATH?

I am experiencing the same issue, but the referenced classes are not .groovy classes. They are regular java classes.

If so, is there a snapshot build available for the latest in CVS? It's mentioned on the site (http://groovy.codehaus.org/Download) but I can't seem to find it. I'm trying to avoid buggering with Maven.

Thanks!

Show
Arjumand Bonhomme added a comment - Would this bug also apply to ANY classes that are specified in CLASSPATH? I am experiencing the same issue, but the referenced classes are not .groovy classes. They are regular java classes. If so, is there a snapshot build available for the latest in CVS? It's mentioned on the site (http://groovy.codehaus.org/Download) but I can't seem to find it. I'm trying to avoid buggering with Maven. Thanks!
Hide
blackdrag blackdrag added a comment -

This patch was only for source script files.

Show
blackdrag blackdrag added a comment - This patch was only for source script files.
Hide
Arjumand Bonhomme added a comment -

So does that mean that it would still affect regular .class files and jars on the classpath?

That is the behavior I'm experiencing with a build from source as of yesterday, although I still need to simpler test.

Show
Arjumand Bonhomme added a comment - So does that mean that it would still affect regular .class files and jars on the classpath? That is the behavior I'm experiencing with a build from source as of yesterday, although I still need to simpler test.
Hide
Arjumand Bonhomme added a comment -

this seems to still be an issue for regular .class files on the class path

Show
Arjumand Bonhomme added a comment - this seems to still be an issue for regular .class files on the class path
Hide
Arjumand Bonhomme added a comment -

My last post meant I did the test below. For debuggin purposes, I modified groovy/bin/startGroovy to echo the classpath being used.
$>cat Tool.java
class Tool
{
public int getNumber()

{ return 1; }

}
$>ls *.class
Tool.class
$>CLASSPATH=.
$>export CLASSPATH
$>groovy -e "assert 1==new Tool.getNumber()"
classpath: /usr/local/groovy/lib/groovy-starter.jar:.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, script_from_command_line: 1: unable to resolve class Tool.getNumber
@ line 1, column 11.
1 Error

Show
Arjumand Bonhomme added a comment - My last post meant I did the test below. For debuggin purposes, I modified groovy/bin/startGroovy to echo the classpath being used. $>cat Tool.java class Tool { public int getNumber() { return 1; } } $>ls *.class Tool.class $>CLASSPATH=. $>export CLASSPATH $>groovy -e "assert 1==new Tool.getNumber()" classpath: /usr/local/groovy/lib/groovy-starter.jar:. org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, script_from_command_line: 1: unable to resolve class Tool.getNumber @ line 1, column 11. 1 Error
Hide
Arjumand Bonhomme added a comment -

Okay. No problems. All user error.

The last post had a code error, which is why the example wouldn't work.
The line: $>groovy -e "assert 1==new Tool.getNumber()"
Should have been: $>groovy -e "assert 1==new Tool().getNumber()"

and that would have worked.

However, I also found the real cause of my problem. It is covered here: http://jira.codehaus.org/browse/GROOVY-1173

In my original code, I was attempting to use the class: com.my.packagename.Example
and had the import statement: import com.my.packagename;
instead of: import com.my.packagename.*;
and later in the script my line: myVar = new Example();
was failing.

So the silently failing import statement allowed me to keep thinking my classpath wasn't being recognized.

Sorry for the extra chatter.

Show
Arjumand Bonhomme added a comment - Okay. No problems. All user error. The last post had a code error, which is why the example wouldn't work. The line: $>groovy -e "assert 1==new Tool.getNumber()" Should have been: $>groovy -e "assert 1==new Tool().getNumber()" and that would have worked. However, I also found the real cause of my problem. It is covered here: http://jira.codehaus.org/browse/GROOVY-1173 In my original code, I was attempting to use the class: com.my.packagename.Example and had the import statement: import com.my.packagename; instead of: import com.my.packagename.*; and later in the script my line: myVar = new Example(); was failing. So the silently failing import statement allowed me to keep thinking my classpath wasn't being recognized. Sorry for the extra chatter.

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: