[ 
https://issues.apache.org/jira/browse/GROOVY-12020?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18084619#comment-18084619
 ] 

ASF GitHub Bot commented on GROOVY-12020:
-----------------------------------------

paulk-asert merged PR #2566:
URL: https://github.com/apache/groovy/pull/2566




> EnumSet .plus() regression in Groovy 4
> --------------------------------------
>
>                 Key: GROOVY-12020
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12020
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.32
>            Reporter: Anton Panikov
>            Priority: Major
>
> EnumSet.plus() method stopped working after upgrading to Groovy 4, but it is 
> working in Groovy 5. All tests done using JDK 25, although I tried 11 with 
> the same result.
> It is a runtime exception and the code need to access newly created EnumSet:
> {code:groovy}
> package test
> import groovy.transform.CompileStatic
> enum EnumTest {
>     ONE,
>     TWO,
>     THREE,
>     FOUR,
>     FIVE,
>     SIX,
>     SEVEN,
>     EIGHT,
>     NINE
>     public static final EnumSet<EnumTest> firstSet = EnumSet.of(ONE, TWO, 
> THREE, FOUR, FIVE)
>     public static final EnumSet<EnumTest> secondSet = firstSet + SIX
> }
> @CompileStatic
> class Application {
>     static void main(String[] args) {
>         println EnumTest.secondSet
>         println 'ok'
>     }
> }
> {code}
> It is working fine in Groovy 3.0.25 and 5.0.6. But in Groovy 4.0.32, it is 
> throwing an exception:
> {code:groovy}
> Exception in thread "main" java.lang.ExceptionInInitializerError
>     at test.Application.main(Application.groovy:27)
> Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: 
> Cannot cast object '[ONE, TWO, THREE, FOUR, FIVE, SIX]' with class 
> 'java.util.LinkedHashSet' to class 'java.util.EnumSet' due to: 
> groovy.lang.GroovyRuntimeException: Could not find matching constructor for: 
> java.util.EnumSet(test.EnumTest, test.EnumTest, test.EnumTest, test.EnumTest, 
> test.EnumTest, test.EnumTest)
>     at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:413)
>     at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:326)
>     at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnCollection(DefaultTypeTransformation.java:284)
>     at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:231)
>     at 
> org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
>     at test.EnumTest.<clinit>(Application.groovy:19)
>     ... 1 more
>     Suppressed: groovy.lang.GroovyRuntimeException: Could not find matching 
> constructor for: java.util.EnumSet(LinkedHashSet)
>         at 
> groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1915)
>         at 
> groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1684)
>         at 
> org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:676)
>         at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:389)
>         ... 6 more
> {code}
> OS: Red Hat Enterprise Linux 8.9 (Ootpa)
> JDK: OpenJDK Runtime Environment Temurin-25.0.3+9 (build 25.0.3+9-LTS)
> and 11.0.20



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

Reply via email to