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

SwitchPoint().guardWithTest throws IAE if target and fallback are not the same method type

XMLWordPrintable

      The javadoc for the java.dyn.SwitchPoint.guardWithTest method states that "The target and fallback must be of exactly the same method type...", but unfortunately does not describe in javadoc any exceptions which can be thrown when the condition doesn't meet.

      Please note that the implementation throws IllegalArgumentException in such case:

      $ cat guardWithTestIAE.java
      import java.dyn.*;
      import static java.dyn.MethodType.*;
      import static java.dyn.MethodHandles.*;

      public class guardWithTestIAE {

          public static void main(String[] args) {
              new SwitchPoint().guardWithTest(
                      exactInvoker(methodType(void.class)),
                      exactInvoker(methodType(int.class))) ;
          }

      }

      $ javac guardWithTestIAE.java
      $ java -showversion -verify -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic guardWithTestIAE
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b135)
      Java HotSpot(TM) Server VM (build 21.0-b05, mixed mode)

      Exception in thread "main" java.lang.IllegalArgumentException: target and fallback types must match: (MethodHandle)void != (MethodHandle)int
              at sun.dyn.MemberName.newIllegalArgumentException(MemberName.java:511)
              at java.dyn.MethodHandles.misMatchedTypes(MethodHandles.java:2028)
              at java.dyn.MethodHandles.guardWithTest(MethodHandles.java:2012)
              at java.dyn.SwitchPoint.guardWithTest(SwitchPoint.java:140)
              at guardWithTestIAE.main(guardWithTestIAE.java:8)

      It seems that the implementation behaviour should be described in the javadoc with something like:
          "Throws: IllegalArgumentException - if the target and fallback are not exactly the same method type."

            Unassigned Unassigned
            ygaevsky Yuri Gaevsky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: