javac generics bug (review-id 2356418)

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Oct 8 09:24:38 PDT 2012


On 08/10/12 15:39, Chris Dennis wrote:
> Hi,
>
> I just stumbled across a javac generics issue whereby the following class fails to compile:
>
> public class GenericTest {
>    
>      public Object foo(Callable<? extends Object[]> foo) throws Exception {
> 	return foo.call()[0];
>      }
> }
>
> with:
>
> GenericTest.java:6: error: array required, but CAP#1 found
> 	return foo.call()[0];
> 	                 ^
>    where CAP#1 is a fresh type-variable:
>      CAP#1 extends Object[] from capture of ? extends Object[]
> 1 error
>
> You can however access .length on the ? extends Object[] typed return without any problems.
>
> I've filed this on bugs.sun.com (2356418), but figured I would raise the issue here too since it looks like a regression that happened in 1.6 and I have a very simple reproducible test case.
Thx - it looks like the routine that checks if the type of an array 
access expression is really an array doesn't factor captured types...

public boolean isArray(Type t) {
         while (t.tag == WILDCARD) //this should check for captured 
types too
             t = upperBound(t);
         return t.tag == ARRAY;
     }

Maurizio
>
> Regards,
>
> Chris Dennis




More information about the compiler-dev mailing list