[
https://issues.apache.org/jira/browse/GROOVY-11930?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tommi Ratamaa updated GROOVY-11930:
-----------------------------------
Description:
Runtime error related to dynamic invocation causing
java.lang.IllegalArgumentException: argument type mismatch exception internally
caused by java.lang.ClassCastException: Cannot cast
org.codehaus.groovy.runtime.wrappers.PojoWrapper to java.lang.String when
calling a private static method with null value (even with explicit casting).
Simplified code example that have worked with Groovy 3, Groovy 4 and works with
@CompileStatic and if build as Java code with JDK21:
{code:java}
class GroovyBug {
//@CompileStatic // would fix it
static String failing(Map<String, String> input, Collection<String> fields)
{
return fields.stream().map(f -> toEntry((String) input.get(f)))
.collect(Collectors.joining(''))
}
private static String toEntry(String value) {
if (value == null || value.isEmpty()) {
return '0'
}
value.getBytes('UTF-8').length + value
}
static void main(String[] args) {
// Field c with (String) null value causes runtime exception calling
toEntry method:
failing([a: '1', b: '2', c: null, d: '4'], ['a', 'b', 'c', 'd'])
/*
Exception: java.lang.IllegalArgumentException: argument type mismatch
java.lang.IllegalArgumentException: argument type mismatch
at GroovyBug$_failing_closure1.doCall(GroovyBug.groovy:7)
at jdk.proxy1/jdk.proxy1.$Proxy15.apply(Unknown Source)
at GroovyBug.failing(GroovyBug.groovy:8)
at GroovyBug.main(GroovyBug.groovy:19)
With debugger found caused by:
java.lang.ClassCastException: Cannot cast
org.codehaus.groovy.runtime.wrappers.PojoWrapper to java.lang.String
at java.base/java.lang.Class.cast(Class.java:4069)
at
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:338)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:274)
at
org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:318)
at GroovyBug$_failing_closure1.doCall(GroovyBug.groovy:7)
at
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
*/
}
} {code}
was:
Runtime error related to dynamic invocation causing
java.lang.IllegalArgumentException: argument type mismatch exception internally
caused by java.lang.ClassCastException: Cannot cast
org.codehaus.groovy.runtime.wrappers.PojoWrapper to java.lang.String when
calling a private static method with null value (even with explicit casting).
Simplified code example that have worked with Groovy 3, Groovy 4 and works with
@CompileStatic and if build as Java code with JDK21:
{code:java}
class GroovyBug1 {
//@CompileStatic // would fix it
static String failing(Map<String, String> input, Collection<String> fields)
{
return fields.stream().map(f -> toEntry((String) input.get(f)))
.collect(Collectors.joining(''))
}
private static String toEntry(String value) {
if (value == null || value.isEmpty()) {
return '0'
}
value.getBytes('UTF-8').length + value
}
static void main(String[] args) {
// Field c with (String) null value causes runtime exception calling
toEntry method:
failing([a: '1', b: '2', c: null, d: '4'], ['a', 'b', 'c', 'd'])
/*
Exception: java.lang.IllegalArgumentException: argument type mismatch
java.lang.IllegalArgumentException: argument type mismatch
at GroovyBug1$_failing_closure1.doCall(GroovyBug1.groovy:7)
at jdk.proxy1/jdk.proxy1.$Proxy15.apply(Unknown Source)
at GroovyBug1.failing(GroovyBug1.groovy:8)
at GroovyBug1.main(GroovyBug1.groovy:19) With debugger
found caused by:
java.lang.ClassCastException: Cannot cast
org.codehaus.groovy.runtime.wrappers.PojoWrapper to java.lang.String
at java.base/java.lang.Class.cast(Class.java:4069)
at
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:338)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:274)
at
org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:318)
at GroovyBug1$_failing_closure1.doCall(GroovyBug1.groovy:7)
at
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
*/
}
} {code}
> Static method call with null with value and casting fails
> ---------------------------------------------------------
>
> Key: GROOVY-11930
> URL: https://issues.apache.org/jira/browse/GROOVY-11930
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 5.0.5
> Environment: Groovy 5.0.5, groovy-eclipse-compiler 3.9.1,
> groovy-eclipse-batch 5.0.5-01, JDK 21, macOS 26
> Reporter: Tommi Ratamaa
> Priority: Major
>
> Runtime error related to dynamic invocation causing
> java.lang.IllegalArgumentException: argument type mismatch exception
> internally caused by java.lang.ClassCastException: Cannot cast
> org.codehaus.groovy.runtime.wrappers.PojoWrapper to java.lang.String when
> calling a private static method with null value (even with explicit casting).
> Simplified code example that have worked with Groovy 3, Groovy 4 and works
> with @CompileStatic and if build as Java code with JDK21:
> {code:java}
> class GroovyBug {
> //@CompileStatic // would fix it
> static String failing(Map<String, String> input, Collection<String>
> fields) {
> return fields.stream().map(f -> toEntry((String) input.get(f)))
> .collect(Collectors.joining(''))
> }
> private static String toEntry(String value) {
> if (value == null || value.isEmpty()) {
> return '0'
> }
> value.getBytes('UTF-8').length + value
> }
> static void main(String[] args) {
> // Field c with (String) null value causes runtime exception calling
> toEntry method:
> failing([a: '1', b: '2', c: null, d: '4'], ['a', 'b', 'c', 'd'])
> /*
> Exception: java.lang.IllegalArgumentException: argument type mismatch
> java.lang.IllegalArgumentException: argument type mismatch
> at GroovyBug$_failing_closure1.doCall(GroovyBug.groovy:7)
> at jdk.proxy1/jdk.proxy1.$Proxy15.apply(Unknown Source)
> at GroovyBug.failing(GroovyBug.groovy:8)
> at GroovyBug.main(GroovyBug.groovy:19)
> With debugger found caused by:
> java.lang.ClassCastException: Cannot cast
> org.codehaus.groovy.runtime.wrappers.PojoWrapper to java.lang.String
> at java.base/java.lang.Class.cast(Class.java:4069)
> at
> java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
> at java.base/java.lang.reflect.Method.invoke(Method.java:580)
> at
> org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:338)
> at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:274)
> at
> org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:318)
> at GroovyBug$_failing_closure1.doCall(GroovyBug.groovy:7)
> at
> java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
> */
> }
> } {code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)