JDK-7032475 : SwitchPoint().guardWithTest throws IAE if target and fallback are not the same method type
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2011-03-30
  • Updated: 2012-03-22
  • Resolved: 2011-05-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Description
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."

Comments
EVALUATION Yes, this need to be documented. The observed behavior is intended. Folding this into 7032323.
13-05-2011