You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2025/07/25 18:41:00 UTC

[jira] [Closed] (GROOVY-11719) Generics Compilation Bug

     [ https://issues.apache.org/jira/browse/GROOVY-11719?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles closed GROOVY-11719.
--------------------------------
    Fix Version/s: 5.0.0-beta-3
       Resolution: Fixed

https://github.com/apache/groovy/commit/2fa3794c315550ccadc64136ee50e9b6dcc46338

> Generics Compilation Bug
> ------------------------
>
>                 Key: GROOVY-11719
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11719
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 4.0.28
>            Reporter: Jonny Carter
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 5.0.0-beta-3
>
>
> In some cases when compiling scripts dealing with generic classes, the {{ResolveVisitor}} can throw an {{UnsupportedOperationException}} by trying to put entries in an immutable empty map.
> This is the same issue I raised on the [release thread for 4.0.28|https://lists.apache.org/thread/3srdsx4q3ktmxq5rb3t6jhon7qdfvcwb].
> Raised a PR with an automated test to reproduce the issue at [https://github.com/apache/groovy/pull/2270], along with a suggested fix. The test to reproduce the error looks like this:
> {code:java}
>     @Test
>     void testRecompilingWithGenericsAndConstants() {
>         MapFileSystem.instance.modFile('BaseClass.groovy', 'class BaseClass<T> {}', gse.@time)
>         def tertiaryClassText = '''
>             class NotGeneric {
>                 /**
>                  * Not typed on purpose - if typed as String then NotGeneric is no longer a dependency of
>                  * ParameterisedClass for some reason...
>                  */
>                 public static final Object CONSTANT = "not generic"
>             }
>         '''
>         MapFileSystem.instance.modFile('NotGeneric.groovy', tertiaryClassText, gse.@time)
>         def subClassText = '''
>             class SubClass extends BaseClass<String> {
>                 public static final String CONSTANT = NotGeneric.CONSTANT
>             }
>         '''
>         MapFileSystem.instance.modFile('SubClass.groovy', subClassText, gse.@time)
>         MapFileSystem.instance.modFile('scriptUsingGeneric.groovy', 'SubClass.CONSTANT', gse.@time)
>         gse.loadScriptByName('scriptUsingGeneric.groovy')
>         sleep 1000
>         // make a change to the sub-class so that it gets recompiled
>         MapFileSystem.instance.modFile('SubClass.groovy', subClassText + '\n', gse.@time)
>         gse.loadScriptByName('scriptUsingGeneric.groovy')
>     }
> {code}
> The root cause error is:
> {code:java}
> Caused by: java.lang.UnsupportedOperationException at java.base/java.util.AbstractMap.put(AbstractMap.java:209)
>  at org.codehaus.groovy.control.ResolveVisitor.resolveGenericsHeader(ResolveVisitor.java:1452)
>  at org.codehaus.groovy.control.ResolveVisitor.resolveGenericsHeader(ResolveVisitor.java:1409) 
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)