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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P5
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 12
    • Component/s: core-libs
    • Labels:

      Description

      "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);
      ===============================================

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: