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

IllegalArgumentException when MH would have too many parameters is not specified for several methods

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 12
    • 9
    • core-libs

      "Arity limits" section of MethodHandle Javadoc (http://download.java.net/java/jdk9/docs/api/java/lang/invoke/MethodHandle.html#maxarity) discusses the general constraint on the arity of method handles.
      Many adapter methods of MethodHandle and MethodHandles explicitly specify IllegalArgumentException if the constraint is violated, but some don't.

      Lookup.find*(...) factories don't specify the possibility of exceeding the arity limit when a method with 255 parameters is looked up.

      Several methods in MethodHandles class also don't specify that IAE:
      dropArgumentsToMatch
      empty
      explicitCastArguments
      permuteArguments
      varHandleInvoker
      varHandleExactInvoker

      Examples of the calls that lead to IAE:
      ===============================================
      Class<?>[] classes254 = IntStream.range(0, 254)
              .mapToObj(i -> int.class)
              .toArray(Class[]::new);
      MethodType mt254 = methodType(void.class, classes254);
      MethodType mt255 = mt254.appendParameterTypes(int.class);

      // all calls below throw IllegalArgumentException

      dropArgumentsToMatch(
              empty(mt254),
              0,
              mt255.parameterList(),
              0
      );
      empty(mt255);
      explicitCastArguments(
              empty(mt254),
              mt254.dropParameterTypes(0, 1).insertParameterTypes(0, long.class)
      );
      permuteArguments(
              empty(methodType(void.class)),
              mt255
      );
      varHandleInvoker(VarHandle.AccessMode.GET, mt254);
      varHandleExactInvoker(VarHandle.AccessMode.GET, mt254);
      ===============================================

            vtheeyarath Vivek Theeyarath (Inactive)
            slukyanov Stanislav Lukyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: