[
https://issues.apache.org/jira/browse/GROOVY-9988?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17315865#comment-17315865
]
Paul King commented on GROOVY-9988:
-----------------------------------
Perhaps we need a better reproducer of your problem. I get the same behavior
for your script for Groovy 4.0.0-snapshot, 3.0.7, 2.5.14, 2.5.8 and 2.4.20.
> Field is given precedence over getter
> -------------------------------------
>
> Key: GROOVY-9988
> URL: https://issues.apache.org/jira/browse/GROOVY-9988
> Project: Groovy
> Issue Type: Bug
> Reporter: Benedikt Ritter
> Priority: Major
> Attachments: test.groovy
>
>
> If a method references a property and there is a field and a getter for that
> field, the field is given precedence over the getter. This is problematic if
> the getter does some lazy initialization.
> Executing the attached script on Groovy 3.0.7 results in the following error:
> {code:java}
> ❯ groovy test.groovy
> Caught: java.lang.NullPointerException: Cannot invoke method length() on null
> object
> java.lang.NullPointerException: Cannot invoke method length() on null object
> at Test.run(test.groovy:12)
> at Test$run.call(Unknown Source)
> at test.run(test.groovy:16)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> {code}
> As a work around the code in run() can explicitly call the getter.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)