[
https://issues.apache.org/jira/browse/GROOVY-9982?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Benedikt Ritter updated GROOVY-9982:
------------------------------------
Description:
Having a method in a base class and using that method in an assignment in an
inheriting class to assign a field of the same name as that method causes a
NullPointerException.
Try executing the attached script with Groovy 3.0.7. It will yield:
{code:java}
❯ groovy test.groovy
Caught: java.lang.NullPointerException
java.lang.NullPointerException
at Child.setup(test.groovy:11)
at Child$setup.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 method call to foo() can explicitly be prefixed with
`super.`
was:
Having a method in a base class and using that method in an assignment in an
inheriting class to assign a field of the same name as that method causes a
NullPointerException.
Try executing the attached script with Groovy 3.0.7. It will yield:
{code:java}
❯ groovy test.groovy
Caught: java.lang.NullPointerException
java.lang.NullPointerException
at Child.setup(test.groovy:11)
at Child$setup.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}
> Can't assign a field with the result of a method call of the same name from a
> base class
> ----------------------------------------------------------------------------------------
>
> Key: GROOVY-9982
> URL: https://issues.apache.org/jira/browse/GROOVY-9982
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 3.0.7
> Reporter: Benedikt Ritter
> Priority: Major
> Attachments: test.groovy
>
>
> Having a method in a base class and using that method in an assignment in an
> inheriting class to assign a field of the same name as that method causes a
> NullPointerException.
> Try executing the attached script with Groovy 3.0.7. It will yield:
> {code:java}
> ❯ groovy test.groovy
> Caught: java.lang.NullPointerException
> java.lang.NullPointerException
> at Child.setup(test.groovy:11)
> at Child$setup.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 method call to foo() can explicitly be prefixed with
> `super.`
--
This message was sent by Atlassian Jira
(v8.3.4#803005)