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/16 23:15:01 UTC

[groovy] branch master 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 master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new bad02b2  GROOVY-7494: ArrayStoreException assigning GStringImpl to String[] when using Indy
bad02b2 is described below

commit bad02b2f8d9ba3906321af2cf2ffd8abbb51a954
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Oct 14 20:15:07 2020 +1000

    GROOVY-7494: ArrayStoreException assigning GStringImpl to String[] when using Indy
---
 .../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 556d584..9cb7c74 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
@@ -58,6 +58,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 ec1c714..f19c0d4 100644
--- a/src/test/groovy/GStringTest.groovy
+++ b/src/test/groovy/GStringTest.groovy
@@ -594,6 +594,13 @@ class GStringTest extends GroovyTestCase {
         assert gstring.toString() == 'Green eggs and ham'
     }
 
+    // GROOVY-7494
+    void testGStringCoercionForArrayPutAt() {
+        String[] fubar = new String[1]
+        fubar[0] = "x${'y'}"
+        assert fubar.toString() == '[xy]'
+    }
+
     void testGStringLiteral() {
         def gstr = "a${'1'}"
         assert gstr.toString() === gstr.toString()