Benedikt Ritter created GROOVY-9988:
---------------------------------------

             Summary: 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
         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)

Reply via email to