[ https://issues.apache.org/jira/browse/GROOVY-11719?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jonny Carter updated GROOVY-11719: ---------------------------------- Description: 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} was: 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} > 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 > Priority: Major > > 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)