Groovy No signature of method calling Java library

As many questions begin, this is driving me crazy.

I have a homegrown StarTeam java library. I have one static method like this:

public static Label getLatestDeploymentLabel(com.starbase.starteam.File child) {
 // blah
}

The method works as expected when I call it from java. When I call it from Groovy, I get:

Caught: groovy.lang.MissingMethodException: 
No signature of method: static pkg.starteam.StarTeamUtils.getLatestDeploymentLabel() 
is applicable for argument types: (com.starbase.starteam.File) 
values: [FILENAME-FOO.sql] at starteam.run(starteam.groovy:54)

I put in a println right before I call that method:

chgset.elements().each() { item ->
  println "type of item is ${item.class.getName()}"
  def latestlabel = StarTeamUtils.getLatestDeploymentLabel(item)
}

And confirm that, in fact, it’s iterating what I expect it’s iterating over:

type of item is com.starbase.starteam.File

I’ve seen a few different similar issues in other posts relating to static methods and the responses are along the lines of “are you sure it’s a static method?”. I’m sure it’s a static method.

There isn’t much groovy code to this. What there is of it is all contained in a single script in the default package. The main method is then called implicitly and it’s in the body of the script class that the call out to the java library is made. I set the classpath in a DOS batch wrapper script, e.g.:

SET INITIALCLASSPATH=%CLASSPATH%
SET NEWCP=c:/libs/etc.jar;c:/etc/etc.jar
SET GROOVYPATH=c:/groovy.bat
SET CLASSPATH=%NEWCP%
%GROOVYPATH% %*
SET CLASSPATH=%INITIALCLASSPATH%

I created a simple situation which I think emulates my situation.

C:appsgroovy-1.8.6scripts>type Other.java
class Other {
    private String name = "notset";
    public Other(String name) {
        this.name = name;
        System.out.println("Created an other");
    }
    public String toString() {
        return name;
    }
}
C:appsgroovy-1.8.6scripts>type ThingList.java
import java.util.ArrayList;
import java.util.Iterator;

class ThingList {
    ArrayList ourlist = new ArrayList<Other>();
    public ThingList(){}
    public ArrayList add(Other thing) {
        ourlist.add(thing);
        return ourlist;
    }
    public Iterator iterator(){
        return ourlist.iterator();
    }
}
C:appsgroovy-1.8.6scripts>type JavaLib.java
class JavaLib {
    public JavaLib() {}
    public static ThingList getThingList(Other thing) {
        ThingList tl = new ThingList();
        Other one = new Other("extra one");
        tl.add(thing);
        tl.add(one);
        return ThingList;
    }
}
C:appsgroovy-1.8.6scripts>type testthing.groovy
def myOther = new Other("A new other")
println "type of myOther is ${myOther.class.getName()}"
def myList = getThingList(myOther)
myList.each() {
  println it
}
C:appsgroovy-1.8.6scripts>type wrapper.bat
@ECHO OFF
SET INITIALCLASSPATH=%CLASSPATH%
SET GROOVY=C:appsgroovy-1.8.6bingroovy.bat
SET CP=.
SET CLASSPATH=%CP%

%GROOVY% %*

SET CLASSPATH=%INITIALCLASSPATH%
C:appsgroovy-1.8.6scripts>wrapper.bat testthing.groovy
Created an other
type of myOther is Other
Caught: groovy.lang.MissingMethodException: No signature of method: testthing.ge
tThingList() is applicable for argument types: (Other) values: [A new other]
groovy.lang.MissingMethodException: No signature of method: testthing.getThingLi
st() is applicable for argument types: (Other) values: [A new other]
        at testthing.run(testthing.groovy:3)

C:appsgroovy-1.8.6scripts>

Any insights or suggestions would be greatly appreciated!

AndyJ

Answer

Without a way to reproduce, it’s impossible to say for sure what the problem is. One possibility is that it is a class loading problem. Is the Groovy code contained in a regular Groovy class that’s sitting on the class path, or does the Groovy code get loaded dynamically (e.g. by using GroovyShell)?

Leave a Reply

Your email address will not be published. Required fields are marked *