[ https://issues.apache.org/jira/browse/GROOVY-7865?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15333361#comment-15333361 ]
Paul King commented on GROOVY-7865: ----------------------------------- I should point out that any transforms that use {{GenericsUtils.parameterizeType()}} or {{GenericsUtils.createGenericsSpec()}} are also subject to this error. There are currently about 20 such usages. > Better error message in the presence of Generics arity errors > ------------------------------------------------------------- > > Key: GROOVY-7865 > URL: https://issues.apache.org/jira/browse/GROOVY-7865 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.4.7 > Reporter: Paul King > > Currently there are many places in the codebase which make assumptions that > they are working with valid generics information. Generics information is > checked but not until the classgen phase. Consequently, we get a very > uninformative ArrayIndexOutOfBoundsException from the compiler - either along > with or instead of the subsequent generics checking. These are all examples > which should fail compilation since I have intentionally tried to instantiate > the generics type with an incorrect number of parameters. It is just the > error message which is not currently useful and masking the subsequent > message that would occur had not the exception got in the way. > Example with TraitComposer: > {code} > class MyNames implements Queue<Integer, String> { } > // java.lang.ArrayIndexOutOfBoundsException: 1 > // TraitComposer calls GenericsUtils.parameterizeType() > // which calls GenericsUtils.createGenericsSpec() > {code} > Example with StaticTypeCheckingVisitor: > {code} > @CompileStatic > def foo() { > List<String> ss = new LinkedList<Integer, String>() > } > // => java.lang.ArrayIndexOutOfBoundsException: 1 > {code} > Example with Verifier: > {code} > class MyNames extends Queue<Integer, String> { } > {code} > which gives > {noformat} > 2 compilation errors: > The class java.util.Queue refers to the class java.util.Queue and uses 2 > parameters, but the referred class needs 1 > at line: 5, column: 23 > Exception thrown > java.lang.ArrayIndexOutOfBoundsException: 1 > at > org.codehaus.groovy.ast.tools.GenericsUtils.createGenericsSpec(GenericsUtils.java:410) > {noformat} > So we get one error from the generics checking but then continue on to the > Verifier. > I suspect the fix for this is to move just the arity checking part of that > visitor to an earlier phase. -- This message was sent by Atlassian JIRA (v6.3.4#6332)