Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Not A Bug
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:Linux 2.6.9-78.0.0.0.1.ELsmp #1 SMP Fri Jul 25 14:41:56 EDT 2008 i686 i686 i386 GNU/Linux
-
Number of attachments :
Description
Sdklib.groovy :
package odilib
public class Sdklib extends Framework {
def test() {
throw new ObjectAlreadyExists ('some text')
}
}
public class ObjectAlreadyExists extends Exception {}
=========================================
my_script.groovy :
import odilib.*
def x = new Sdklib ()
try
catch (ObjectAlreadyExists e) {}
Run as :
groovy my_script.groovy
Error :
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, my_script.groovy: xx: unable to resolve class ObjectAlreadyExists
@ line xx, column 5.
} catch (ObjectAlreadyExists e) {
^
1 error
As you could see, Sdklib.groovy has 2 classes that belong to package odilib, the second one defines exception.
From the outside script the first class named after the script Sdklib is visible, but not the second one corresponding to the exception.
Issue Links
- is related to
-
GROOVY-1328
cleanup strategy of choosing the class to execute when a file contains multiple classes
-
You cannot expect Groovy to have the second sight. when you refer to a class ObjectAlreadyExists, then Groovy expects this either as ready class known by the loader (in your case as .class file) or as .groovy somewhere in the classpath. But Groovy would look for a ObjectAlreadyExists.groovy, it cannot know that Sdklib.groovy actually contains the class. You have a slight achnce by referencing Sdklib, but the compiler will first go through with your file and then see what is actually in Sdklib.groovy.