JDK-7018894 : JSR 292 method handle collector transform does not work correctly on subtypes of Object[]
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2011-02-11
  • Updated: 2011-05-17
  • Resolved: 2011-05-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Relates :  
Description
The asCollector transform does not respect the type argument.
When it collects a series of arguments, it always puts it into an Object[] array.
This causes a CCE if the ultimate target requires a more specific type, such as String[].

Here is a customer report:

http://mail.openjdk.java.net/pipermail/mlvm-dev/2011-February/002439.html

Also, this reproduces the bug:

MethodHandle asList = lookup().
    findStatic(Arrays.class, "asList", methodType(List.class, Object[].class));

asList = asList.asType(methodType(List.class, String[].class)).
    asVarargsCollector(String[].class);

System.out.println(asList.invokeWithArguments("a", "b", "c"));

Comments
EVALUATION This should be simple to fix when we have a fix for the larger issue, 6983728.
12-02-2011

WORK AROUND Use Object... varargs instead of String... varargs, etc. In some cases, <T> T... varargs will help, since T erases to Object.
11-02-2011