[ 
https://issues.apache.org/jira/browse/GROOVY-12671?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18141674#comment-18141674
 ] 

ASF GitHub Bot commented on GROOVY-12671:
-----------------------------------------

paulk-asert closed pull request #3192: GROOVY-12671: skip a null owner or 
delegate when resolving closure properties
URL: https://github.com/apache/groovy/pull/3192




> Closure property access throws NullPointerException instead of falling 
> through to the delegate when the owner is null
> ---------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12671
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12671
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.33, 5.0.8, 5.1.3, 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> {code:groovy}
> class D { def bar = 'delegate' }
> def c = { -> bar }.dehydrate()
> c.delegate = new D()
> assert c() == 'delegate'
> {code}
> *Actual:* {{java.lang.NullPointerException: Cannot get property 'bar' on null 
> object}}. A write ({{bar = 1}}) throws {{Cannot set property 'bar' on null 
> object}}, and so does {{rehydrate(d, null, null)}}.
> *Expected:* with OWNER_FIRST (the default) a null owner is skipped and the 
> delegate supplies the property, the same as for method calls (GROOVY-12667). 
> When no non-null candidate remains (both null, or a null target under 
> OWNER_ONLY or DELEGATE_ONLY), MissingPropertyException is thrown, matching 
> the MissingMethodException that method calls give.
> {{Closure.resolveGetProperty}} and {{resolveSetProperty}} skip a null 
> receiver only for DELEGATE_FIRST with a null delegate (GROOVY-1974). Every 
> other null receiver reaches {{NullObject}}. Separately, 
> {{setPropertyTryThese}} tests {{o1 != null}} where it should test {{o2 != 
> null}}, so a missing property on the owner with a null delegate also throws 
> NPE instead of MissingPropertyException.
> Verified on 2.4.15, 3.0.25, 4.0.33, 5.0.8, 6.0.0 and master.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to