You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Benedikt Ritter (Jira)" <ji...@apache.org> on 2021/04/06 15:27:00 UTC
[jira] [Commented] (GROOVY-9988) Field is given precedence over
getter
[ https://issues.apache.org/jira/browse/GROOVY-9988?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17315658#comment-17315658 ]
Benedikt Ritter commented on GROOVY-9988:
-----------------------------------------
[~paulk] so this behavior was intentionally changed between Groovy 2 and Groovy 3? I'm asking because some code in our application that used worked on Groovy 2 does not work anymore because of this issue.
> 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)