Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Trivial
-
Resolution: Fixed
-
Affects Version/s: 1.0-JSR-3
-
Fix Version/s: 1.0-JSR-6
-
Component/s: None
-
Labels:None
-
Environment:groovy jsr03, jdk 142_09
-
Number of attachments :
Description
When using a class that depends on another class that is not available, e.g. like this:
myjar1.jar : contains foo.MyClass1, which depends on bar.MyClass2
myjar2.jar : contains bar.MyClass2
A method in MyClass1:
public MyClass2 amethod(MyClass2 arg) { //...
and only myjar1.jar is on the classpath.
Now, if you do:
def cls = Class.forName('foo.MyClass1')
def m = cls.methods
you get:
Caught: groovy.lang.GroovyRuntimeException: Cannot read property: methods
which is not very informative. The property "methods" exists (i.e. the method getMethods()).
A simple improvement would be to tell what exception caused the reading of the given property to fail. At the moment getCause() on the thrown GroovyRuntimeException returns null.
Im seeing something similar, but with a different message.
These two require two .jars, I only give one of them on the classpath:
#groove-groovy
import opennlp.tools.lang.english.*
def tmp = new SentenceDetector("dss")
#Test.java
import opennlp.tools.lang.english.*;
public class Test {
public static void main(String [ ] args) {
try { SentenceDetector tmp = new SentenceDetector("sadsa"); } catch(java.io.IOException e){ System.out.println(e); }
}
}
javac -cp /home/sandos/projs/nlp/opennlp/opennlp-tools-1.3.0/output/opennlp-tools-1.3.0.jar:. Test.java
Test.java:6: cannot access opennlp.maxent.MaxentModel
file opennlp/maxent/MaxentModel.class not found
SentenceDetector tmp = new SentenceDetector("sadsa");
and
java -cp /home/sandos/projs/nlp/opennlp/opennlp-tools-1.3.0/output/opennlp-tools-1.3.0.jar:. Test
Exception in thread "main" java.lang.NoClassDefFoundError: opennlp/maxent/DataStream
at Test.main(Test.java:6)
respectively, versus
groovy -cp /home/sandos/projs/nlp/opennlp/opennlp-tools-1.3.0/output/opennlp-tools-1.3.0.jar groove.groovy
groove.groovy: 3: unable to resolve class SentenceDetector
@ line 3, column 11.
def tmp = new SentenceDetector("dss")
"Cannot resolve class" is much less useful than the specific error message java and javac gives. This made me as a groovy noob believe class loading was very broken, since
groovy groove.groovy
groove.groovy: 3: unable to resolve class SentenceDetector
@ line 3, column 11.
def tmp = new SentenceDetector("dss")
So, giving no jar and only one of two required jars gives the same message, whereas java doesnt:
java -cp . Test
Exception in thread "main" java.lang.NoClassDefFoundError: opennlp/tools/lang/english/SentenceDetector