You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/10/19 22:48:39 UTC

[groovy] branch GROOVY_2_5_X updated: GROOVY-7494: ArrayStoreException assigning GStringImpl to String[] when using Indy

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


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

commit 1bcfbbe3a91291ad61296b2ebb97b2e35839aef3
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                                | 8 ++++++++
 2 files changed, 10 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 10dc209..aa2448f 100644
--- a/src/test/groovy/GStringTest.groovy
+++ b/src/test/groovy/GStringTest.groovy
@@ -591,4 +591,12 @@ 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]'
+    }
+
 }