Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X ef659512a -> 61284355f


GROOVY-8211: pre-factor avoid AIOOBE with clearer message but real fix to come


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/61284355
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/61284355
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/61284355

Branch: refs/heads/GROOVY_2_6_X
Commit: 61284355fea4dda92b63b0f2458597b9a20b22ce
Parents: ef65951
Author: Paul King <pa...@asert.com.au>
Authored: Thu Apr 12 13:50:08 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Thu Apr 12 13:53:38 2018 +1000

----------------------------------------------------------------------
 .../codehaus/groovy/ast/tools/GenericsUtils.java | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/61284355/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java 
b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
index b562ab8..31f6c6e 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -159,6 +159,11 @@ public class GenericsUtils {
         if (parameterized == null || parameterized.length == 0) return;
         GenericsType[] redirectGenericsTypes = 
node.redirect().getGenericsTypes();
         if (redirectGenericsTypes == null) redirectGenericsTypes = 
parameterized;
+        if (redirectGenericsTypes.length != parameterized.length) {
+            throw new GroovyBugError("Expected earlier checking to detect 
generics parameter arity mismatch" +
+                    "\nExpected: " + node.getName() + 
toGenericTypesString(redirectGenericsTypes) +
+                    "\nSupplied: " + node.getName() + 
toGenericTypesString(parameterized));
+        }
         for (int i = 0; i < redirectGenericsTypes.length; i++) {
             GenericsType redirectType = redirectGenericsTypes[i];
             if (redirectType.isPlaceholder()) {
@@ -185,6 +190,20 @@ public class GenericsUtils {
         }
     }
 
+    private static String toGenericTypesString(GenericsType[] genericsTypes) {
+        if (genericsTypes == null) return "";
+        StringBuilder sb = new StringBuilder("<");
+        for (int i = 0; i < genericsTypes.length; i++) {
+            final GenericsType genericsType = genericsTypes[i];
+            sb.append(genericsType.toString());
+            if (i < genericsTypes.length - 1) {
+                sb.append(",");
+            }
+        }
+        sb.append("> ");
+        return sb.toString();
+    }
+
     /**
      * Interface class nodes retrieved from {@link 
org.codehaus.groovy.ast.ClassNode#getInterfaces()}
      * or {@link org.codehaus.groovy.ast.ClassNode#getAllInterfaces()} are 
returned with generic type

Reply via email to