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

Clarify the throwing of exceptions from ConstantBootstraps.invoke

XMLWordPrintable

      The documentation talks about WrongMethodTypeException in case of mismatched type. It does not mention about reference casting error for return type. JDK fails with ClassCastException for the below code:

      import java.lang.invoke.*;
      public class code {
      public static void main(String[] args) throws Throwable {
      System.out.println("Testing ConstantBoostraps.invoke");

                      ConstantBootstraps.invoke(MethodHandles.lookup(), null, int.class, MethodHandles.lookup().unreflect(code.class.getDeclaredMethod("worker", int[].class)), new code(), 10, 10);
              }

              public Object worker(int... args) {
                     return 0L;
             }

      }


            psandoz Paul Sandoz
            pgundarlahal Prashanthram Gundarlahally
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: