Error when trying to use default value (repeated method calls)

Here's my code:
In the parent app (relevant snippets)

`    @Field Integer earlyFetchMinsDefault = 30`
    input name: "earlyFetchMins", type: "number", title: "", required: true, defaultValue: earlyFetchMinsDefault

def getEarlyFetchMins() {
    log.trace "in get early fetch mins"
    if (earlyFetchMins) return earlyFetchMins
    else return earlyFetchMinsDefault
}

in the child app:
Integer earlyFetchMins = parent.getEarlyFetchMins()

When the child app calls parent.getEarlyFetchMins(), the log is this:


With this unhelpful error message:

Is there a problem with trying to use a default value for a setting that the user has not set yet? How does one go about having a default value that the user can optionally adjust, but still being able to use that value if the user never adjusts it?

Check out number 7 on this page: The Apache Groovy programming language - Style guide

You are in a loop because getEarlyFetchMins() is the same as earlyFetchMins so this line:

if (earlyFetchMins) return earlyFetchMins

will call getEarlyFetchMins() twice and you will continue to loop until you run out of stack space. Rename your input to something else or rename your method to something else.

2 Likes