spec clarification: wildcard array element signature
Alex Buckley
alex.buckley at oracle.com
Mon Oct 24 18:28:28 UTC 2016
First, I don't know why javac is denoting the type of i using A rather
than B, both in the field descriptor and in the Signature attribute. The
field descriptor is specified in JLS8 13.1 as containing "a symbolic
reference to the erasure of the type of the field". Plainly this is
LB$I, and Signature would follow suit.
Second, there is nothing in JLS8 8.1.2 to deny B<?>'s supertype being
A<?[]>, so to speak. But it was never envisaged in JVMS8 4.7.9.1 that
there would be a type parameterized by "array of wildcards". This may be
due to the trickiness of Signature having multiple roles: it reifies
generic type information like B<Y> (where array types are not permitted
as type parameters) in addition to parameterized type information like
A<Y[]> (where array types are permitted as type arguments).
Third, on JDK 9b140, javac crashes if the declaration of i uses a
bounded wildcard for B's type argument -- say B<? extends Number>.I
java.lang.ClassCastException:
com.sun.tools.javac.code.Type$TypeMapping$3 (in module: jdk.compiler)
cannot be cast to
com.sun.tools.javac.code.Type$WildcardType (in module: jdk.compiler)
at
com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.validateAnnotatedType(jdk.compiler at 9-ea/Attr.java:4804)
Looking for others to comment.
Alex
On 10/22/2016 8:15 PM, Liam Miller-Cushon wrote:
> When javac compiles the following program, it writes field i's signature
> as "LA<[*>.I;".
>
> I don't think the grammar in JVMS 4.7.9.1 allows for the element type of
> an array to be a wildcard. Is that a spec bug?
>
> class A<X> { class I {} }
> class Test {
> class B<Y> extends A<Y[]> {}
> B<?>.I i;
> }
More information about the compiler-dev
mailing list