FULL PRODUCT VERSION :
java version " 1.7.0_07 "
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin Chriss-MacBook-Pro.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
Direct array element access (within a single line) of a wildcard generic type with an array typed upper bound fails with the following compilation error:
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
The fails for me on latest 1.7, 1.8 (recent lambda build) and 1.6 but compiles correctly in 1.5:
java version " 1.5.0_30 "
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_30-b03-389-11M3811)
Java HotSpot(TM) Client VM (build 1.5.0_30-161, mixed mode, sharing)
REGRESSION. Last worked in version 5.0
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attempt to compile the source code included with this report.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A successful compilation.
ACTUAL -
Compilation fails with a non-sensical error message.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
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
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.concurrent.Callable;
public class GenericTest {
public Object foo(Callable<? extends Object[]> foo) throws Exception {
return foo.call()[0];
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The following class does compile successfully in all my versions of javac (1.5, 1.6, 1.7, 1.8 (recent lambda branch build):
import java.util.concurrent.Callable;
public class GenericTest {
public Object foo(Callable<? extends Object[]> foo) throws Exception {
Object[] array = foo.call();
return array[0];
}
}