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

Clarify the throwing of exceptions from ConstantBootstraps.invoke

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Clarify exception handling of ConstantBootstraps.invoke, specifically the cases when a WrongMethodTypeException and ClassCastException may occur. In the former case the specification appeals to MethodHandle.asType for adjustment of the return type.

      Specification

      Difference:

      --- a/src/java.base/share/classes/java/lang/invoke/ConstantBootstraps.java  Mon Mar 12 16:09:18 2018 -0700
      +++ b/src/java.base/share/classes/java/lang/invoke/ConstantBootstraps.java  Tue Mar 13 11:27:34 2018 -0700
      @@ -208,20 +208,25 @@
           /**
            * Returns the result of invoking a method handle with the provided
            * arguments.
      +     * <p>
      +     * This method behaves as if the method handle to be invoked is the result
      +     * of adapting the given method handle, via {@link MethodHandle#asType}, to
      +     * adjust the return type to the desired type.
            *
            * @param lookup unused
            * @param name unused
      -     * @param type the type of the value to be returned, which must be
      +     * @param type the desired type of the value to be returned, which must be
            * compatible with the return type of the method handle
            * @param handle the method handle to be invoked
            * @param args the arguments to pass to the method handle, as if with
            * {@link MethodHandle#invokeWithArguments}.  Each argument may be
            * {@code null}.
            * @return the result of invoking the method handle
      -     * @throws WrongMethodTypeException if the handle's return type cannot be
      -     * adjusted to the desired type
      -     * @throws ClassCastException if an argument cannot be converted by
      -     * reference casting
      +     * @throws WrongMethodTypeException if the handle's method type cannot be
      +     * adjusted to take the given number of arguments, or if the handle's return
      +     * type cannot be adjusted to the desired type
      +     * @throws ClassCastException if an argument or the result produced by
      +     * invoking the handle cannot be converted by reference casting
            * @throws Throwable anything thrown by the method handle invocation
            */
           public static Object invoke(MethodHandles.Lookup lookup, String name, Class<?> type,

      New:

      /**
       * Returns the result of invoking a method handle with the provided
       * arguments.
       * <p>
       * This method behaves as if the method handle to be invoked is the result
       * of adapting the given method handle, via {@link MethodHandle#asType}, to
       * adjust the return type to the desired type.
       *
       * @param lookup unused
       * @param name unused
       * @param type the desired type of the value to be returned, which must be
       * compatible with the return type of the method handle
       * @param handle the method handle to be invoked
       * @param args the arguments to pass to the method handle, as if with
       * {@link MethodHandle#invokeWithArguments}.  Each argument may be
       * {@code null}.
       * @return the result of invoking the method handle
       * @throws WrongMethodTypeException if the handle's method type cannot be
       * adjusted to take the given number of arguments, or if the handle's return
       * type cannot be adjusted to the desired type
       * @throws ClassCastException if an argument or the result produced by
       * invoking the handle cannot be converted by reference casting
       * @throws Throwable anything thrown by the method handle invocation
       */
      public static Object invoke(MethodHandles.Lookup lookup, String name, Class<?> type,
                                  MethodHandle handle, Object... args) throws Throwable {

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psandoz Paul Sandoz
                Reporter:
                pgundarlahal Prashanthram Gundarlahally
                Reviewed By:
                Mandy Chung
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: