Presence of a groovy script method depends on its argument

I am making a script traversing page tree structure. For some reasons I switched from python to groovy which is new to me. So this problem could be connected with xwiki script support as well as groovy.

I have a one argument method

  def includeDocWithChildren = {String documentRef ->
    def doc = xwiki.getDocument(documentRef)
    for(child in doc.getChildren()){
        includeDocWithChildren(child)
    }
}

Now I call it

includeDocWithChildren('Main.WebHome')

I get following error

groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.includeDocWithChildren() is applicable for argument types: (String) values: [Main.WebHome]

When the string parameter is without dot (e.x. “Main-WebHome”), the method is found. Could you get me a hint what’s going on?

Edit 2020-05-22: Groovy script updated to contain the bad part. It would be nonsense without it.

Hi, I think your problem is elsewhere from what you’re showing above. I’ve tried it playgroung.xwiki.org with:

{{groovy}}
 def includeDocWithChildren = {String documentRef ->
    def doc = xwiki.getDocument(documentRef)
}

includeDocWithChildren('Main.WebHome')
{{/groovy}}

And it works fine.

Thank you Vincent. I found the bug thanks to you. For need of this question I simplified the code too much. There was a recursive calling which caused the problem. I have learned that a variable needs to be defined before it is called.

The code …

{{groovy}}
def includeDocWithChildren = {String documentRef ->
    def doc = xwiki.getDocument(documentRef)
    for(child in doc.getChildren()) {
        includeDocWithChildren(child)
    }
}

includeDocWithChildren('Main.WebHome')
{{/groovy}}

… should start with

{{groovy}}
def includeDocWithChildren
includeDocWithChildren = {String documentRef ->
    ...
}
{{/groovy}}