[
https://issues.apache.org/jira/browse/GROOVY-8978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17856286#comment-17856286
]
Eric Milles commented on GROOVY-8978:
-------------------------------------
Writing to a non-public field outside the declaring type will require
“copy.@target = …” syntax in Groovy 5.
> NPE when accessing protected method from subclass clone
> -------------------------------------------------------
>
> Key: GROOVY-8978
> URL: https://issues.apache.org/jira/browse/GROOVY-8978
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.5.6
> Reporter: paolo di tommaso
> Assignee: Paul King
> Priority: Major
> Fix For: 3.0.0-beta-1, 2.5.7
>
>
> I'm getting a NPE when running this snippet:
> {code}
> @groovy.transform.CompileStatic
> class LazyMap implements Map<String,Object> {
> @Delegate protected Map<String,Object> target
> LazyMap() {
> target = new HashMap<>()
> }
> }
> @groovy.transform.CompileStatic
> class TaskConfig extends LazyMap implements Cloneable {
> TaskConfig() { }
> TaskConfig clone() {
> def copy = (TaskConfig)super.clone()
> copy.target = new HashMap<>(this.target)
> return copy
> }
> }
> {code}
> The problem is that `this.target` in the clone method is evaluated to `null`.
> It works fine if the classes are not declared CompileStatic. It was also
> working fine with groovy version prior to 2.5.6.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)