Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8155106

MHs.Lookup.findConstructor returns handles for array classes

    Details

      Backports

        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.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  mhaupt Michael Haupt
                  Reporter:
                  mhaupt Michael Haupt
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: