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

MethodHandles.foldArguments handle negative pos

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • core-libs

      A DESCRIPTION OF THE PROBLEM :
      MethodHandles.foldArguments(MethodHandle, Int, MethodHandle) needs 0 based index pos.
      But negative pos triggers ArrayIndexOutOfBoundsException, rather than IAE.

      import java.lang.invoke.MethodHandle;
      import java.lang.invoke.MethodHandles;
      import java.lang.invoke.MethodType;
      import org.testng.annotations.*;

      public class FoldTest {


          @Test(expectedExceptions = IllegalArgumentException.class)
          public void testNegativePosition() throws Throwable {
              MethodHandle target = MethodHandles.lookup().findStatic(FoldTest.class, "target",
                      MethodType.methodType(int.class, int.class, int.class));
              MethodHandle combiner = MethodHandles.lookup().findStatic(FoldTest.class, "combiner",
                      MethodType.methodType(int.class, int.class));
              
              MethodHandles.foldArguments(target, -1, combiner);
          }

          private static int target(int x, int y) { return 0; }
          private static int combiner(int x) { return 0; }
      }


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: