groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winnebeck, Jason" <>
Subject Safe Navigation call: argument expression evaluation
Date Wed, 04 Jan 2017 19:31:59 GMT
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
(, 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.

View raw message