groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Matz <guym...@gmail.com>
Subject Re: Groovy defaults method argument to null?
Date Wed, 04 May 2016 13:35:21 GMT
Annoying.  Thank you!!

So do you people generally leave the single-parameter methods with the
default Groovy behavior?  Or do y'all use the mandatory method trick in the
link above?  Or is there a better way?

Thanks again!

On Tue, May 3, 2016 at 5:23 PM, Shil Sinha <shil.sinha@gmail.com> wrote:

> Yes, though this is specific to methods with one parameter and only occurs
> if the method call is not statically compiled. See
> http://glaforge.appspot.com/article/groovy-default-params-to-avoid-one-argument-methods-being-called-without-params
for
> a discussion.
>
> On Tue, May 3, 2016 at 3:58 PM Guy Matz <guymatz@gmail.com> wrote:
>
>> I have a method that starts like this:
>>
>> class Sidecar {
>>
>>   def static String getVersions(String render_server) {
>>
>>     def rest = new RESTClient('http://' + render_server)
>>
>>     try {
>>
>>       def vpath = *'*/r/api/versions'
>>       log.debug "Hitting http://${render_server}${vpath}"
>>       def resp = rest.get(path:vpath)
>>
>>
>> and when I call it as Sidecar.getVersions('server-name') it works as expected.  When
I "accidentally" call it without a parameter, though, Groovy does not complain until it attempts
the REST call:
>>
>> groovy:000> r = Sidecar.getVersions()
>>
>> 15:49:41.209 [main] DEBUG com.jcrew.jenkins.helpers.Sidecar - Hitting http://*null*/r/api/versions
>>
>>
>> Is Groovy defaulting the parameter to null when it's not supplied?
>>
>>

Mime
View raw message