Octavia Togami created GROOVY-12232:
---------------------------------------
Summary: `GroovyCastException: Cannot cast object PojoWrapper`
when an as coercion is passed directly as an argument to an anonymous inner
class constructor
Key: GROOVY-12232
URL: https://issues.apache.org/jira/browse/GROOVY-12232
Project: Groovy
Issue Type: Bug
Affects Versions: 5.0.8
Reporter: Octavia Togami
This used to work on Groovy 4.0.33, but fails now on 5.0.8:
{code:groovy}
class Test {
Test(Set<String> values) {}
}
new Test(['a'] as Set) {}
{code}
The error is:
{code:sh}
GroovyCastException: Cannot cast object
'org.codehaus.groovy.runtime.wrappers.PojoWrapper@47fbc56'
with class 'org.codehaus.groovy.runtime.wrappers.PojoWrapper' to class
'java.util.Set'
{code}
Without the anon class, coercion (e.g. using {{Set.of(...)}}), if it's stored
in a local var first, or if the class constructor is not statically resolvable;
it works fine.
This was reduced from real code in Gradle:
https://github.com/gradle/gradle/blob/be7b1d956fd466144fbb3a1e268bfd6704205250/platforms/jvm/java-compiler-worker/src/test/groovy/org/gradle/api/internal/tasks/compile/AnnotationProcessingCompileTaskTest.groovy#L58
--
This message was sent by Atlassian Jira
(v8.20.10#820010)