JDK-8155106 : MHs.Lookup.findConstructor returns handles for array classes
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2016-04-26
  • Updated: 2017-05-17
  • Resolved: 2016-04-27
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 8 JDK 9
8u112Fixed 9 b117Fixed
Description
When passing an array class to MHs.Lookup.findConstructor(), that method will return a handle that, when invoked, creates an instance of Object. This is not in concordance with the bytecode behaviour rules for Lookup methods. Rather, a NoSuchMethodException should be thrown.

A sample jshell session follows.

-> import java.lang.invoke.*

-> MethodHandle mh = MethodHandles.lookup().findConstructor(String[].class, MethodType.methodType(void.class));
|  Added variable mh of type MethodHandle with initial value MethodHandle()Object

-> mh.invoke().getClass()
|  Expression value is: class java.lang.Object
|    assigned to temporary variable $3 of type Class<? extends Object>

To round off the fix, and to provide more convenience, corresponding methods for array creation handle generation could be added to MethodHandles.