Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.7
-
None
-
None
Description
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:
class MyNames implements Queue<Integer, String> { } // java.lang.ArrayIndexOutOfBoundsException: 1 // TraitComposer calls GenericsUtils.parameterizeType() // which calls GenericsUtils.createGenericsSpec()
Example with StaticTypeCheckingVisitor:
@CompileStatic def foo() { List<String> ss = new LinkedList<Integer, String>() } // => java.lang.ArrayIndexOutOfBoundsException: 1
Example with Verifier:
class MyNames extends Queue<Integer, String> { }
which gives
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)
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.
Attachments
Issue Links
- is duplicated by
-
GROOVY-6660 invalid generics symbol arity does not lead to compilation error
- Closed
- relates to
-
GROOVY-8211 ArrayIndexOutOfBoundsException at compilation when accessing a generic type with the wrong number of type parameters
- Closed
- links to