You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by "Winnebeck, Jason" <Ja...@windstream.com> on 2017/01/04 19:31:59 UTC
Safe Navigation call: argument expression evaluation
I noticed that safe navigation operator works with assignments and calls x?.value = 123.
But, it seems inconsistent whether or not the RHS side is evaluated. I tried a Groovy console where I called x?.setValue(method()) and method wasn't called, but in my actual app where I do x?.setValue(a.b.c) where a.b is null I get NPE. I found safe navigation operator documentation (http://groovy-lang.org/operators.html#_safe_navigation_operator), but it doesn't specify what happens to expressions in a method call. Is there any behavior I can rely upon? For now I workaround by doing an explicit x != null check, then x.setValue.
Jason Winnebeck
This email message and any attachments are for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message and any attachments.