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

Eric Milles updated GROOVY-10239:
---------------------------------
    Fix Version/s: 3.0.10

> GroovyCastException when @CompileStatic and !in keyword are used together
> -------------------------------------------------------------------------
>
>                 Key: GROOVY-10239
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10239
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 3.0.9
>         Environment: macOs Big Sur 11.5.2
> 2,6 GHz 6-Core Intel Core i7
> Java 11.0.11/16.0.1 (probably reproducible in other version)
>            Reporter: Rodolfo Yanke
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-2, 3.0.10
>
>
> Dear colleagues,
> I've recently updated my projects from 3.0.8 to 3.0.9 and I started getting 
> some GroovyCastExceptions when trying to use *!in* keyword along with 
> CompileStatic annotation:
> {code:groovy}
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
> object 'true' with class 'java.lang.Boolean' to class 'Xyz'
> {code}
> We realised that it only works on 3.0.9 if we remove the CompileStatic 
> annotation(3.0.8 works with and without).
> Here's an example of how to reproduce the exception:
> {code:groovy}
> import groovy.transform.CompileStatic
> /**
>  *  REMOVE @CompileStatic and the main method runs fine for both versions 
> 3.0.8 and 3.0.9.
>  * 'Cannot cast object \'true\' with class \'java.lang.Boolean\' to class 
> \'MyEnum\''
>  *  @CompileStatic only works with 3.0.8
>  */
> @CompileStatic
> class Groovy309Error {
>     static void main(String[] args) {
>         def myObj = new MyObj(status: MyEnum.A)
>         List<MyObj> items = [myObj]
>         def newItems = items.findAll { it.status !in [MyEnum.B] }
>         println newItems
>     }
> }
> enum MyEnum {
>     A, B
> }
> class MyObj {
>     MyEnum status
> }{code}
>  
> Please, forgive me if I missed something on the bug checklist but I think 
> this ticket belongs here.
> Thank you in advance 



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to