You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/10/18 09:53:03 UTC
[groovy] branch GROOVY_3_0_X updated: GROOVY-7494:
ArrayStoreException assigning GStringImpl to String[] when using Indy
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new 7c491df GROOVY-7494: ArrayStoreException assigning GStringImpl to String[] when using Indy
7c491df is described below
commit 7c491df7cdeba81fe528e2005780d94e076f9743
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Oct 14 18:15:07 2020 +0800
GROOVY-7494: ArrayStoreException assigning GStringImpl to String[] when using Indy
(cherry picked from commit bad02b2f8d9ba3906321af2cf2ffd8abbb51a954)
---
.../groovy/runtime/dgmimpl/arrays/ObjectArrayPutAtMetaMethod.java | 2 ++
src/test/groovy/GStringTest.groovy | 7 +++++++
2 files changed, 9 insertions(+)
diff --git a/src/main/java/org/codehaus/groovy/runtime/dgmimpl/arrays/ObjectArrayPutAtMetaMethod.java b/src/main/java/org/codehaus/groovy/runtime/dgmimpl/arrays/ObjectArrayPutAtMetaMethod.java
index 3db454d..55ace06 100644
--- a/src/main/java/org/codehaus/groovy/runtime/dgmimpl/arrays/ObjectArrayPutAtMetaMethod.java
+++ b/src/main/java/org/codehaus/groovy/runtime/dgmimpl/arrays/ObjectArrayPutAtMetaMethod.java
@@ -56,6 +56,8 @@ public class ObjectArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
}
} else if (Character.class.isAssignableFrom(arrayComponentClass)) {
adjustedNewVal = DefaultTypeTransformation.getCharFromSizeOneString(newValue);
+ } else if (String.class.equals(arrayComponentClass) && newValue instanceof GString) {
+ adjustedNewVal = DefaultTypeTransformation.castToType(newValue, arrayComponentClass);
} else if (Number.class.isAssignableFrom(arrayComponentClass)) {
if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) {
Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue);
diff --git a/src/test/groovy/GStringTest.groovy b/src/test/groovy/GStringTest.groovy
index 6b5c24a..663f449 100644
--- a/src/test/groovy/GStringTest.groovy
+++ b/src/test/groovy/GStringTest.groovy
@@ -593,4 +593,11 @@ class GStringTest extends GroovyTestCase {
gstring.strings[1] = ' and '
assert gstring.toString() == 'Green eggs and ham'
}
+
+ // GROOVY-7494
+ void testGStringCoercionForArrayPutAt() {
+ String[] fubar = new String[1]
+ fubar[0] = "x${'y'}"
+ assert fubar.toString() == '[xy]'
+ }
}