JDK-6924638 : MethodHandles.catchException() does not work for user-defined exceptions
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2010-02-09
  • 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
Please see the minimized test below to reproduce the failure:

Minimized test:
===============

$ cat Test.java 
import java.dyn.*;

public class Test {

    public static void meth() {
        System.out.println("Invoked: public static void target()");
    }

    public static void catcher(Throwable e) {
        System.out.println("Invoked: public static void catcher(Throwable e)");
    }

    public static void catcher(MyExc e) {
        System.out.println("Invoked: public static void catcher(MyExc e)");
    }

    public static void main(String[] args) throws Throwable {
        MethodHandle target = MethodHandles.lookup().findStatic(
                Test.class, "meth", MethodType.methodType(void.class));

        MethodHandle handler = MethodHandles.lookup().findStatic(
                Test.class, "catcher", MethodType.methodType(
                        void.class, Throwable.class));

        MethodHandle handler2 = MethodHandles.lookup().findStatic(
                Test.class, "catcher", MethodType.methodType(
                        void.class, MyExc.class));

        try {
            MethodHandles.catchException(target, Throwable.class, handler);
            System.out.println("OKAY");
        } catch (Throwable e) {
            System.out.println("FAILED. Unexpected exception thrown: " + e);
        }

        try {
            MethodHandles.catchException(target, MyExc.class, handler2);
            System.out.println("OKAY");
        } catch (Throwable e) {
            System.out.println("FAILED. Unexpected exception thrown: " + e);
        }
    }
}

$ cat MyExc.java 
public class MyExc extends Throwable {}


Minimized test output:
======================
$ javac  -fullversion Test.java MyExc.java
javac full version "1.7.0-ea-b82"

java -showversion -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic Test
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b82)
Java HotSpot(TM) Server VM (build 17.0-b08, mixed mode)

OKAY
FAILED. Unexpected exception thrown: java.dyn.NoAccessException: cannot access: *.java.dyn.MethodHandle.invoke(MyExc)void

Comments
EVALUATION Looks like a side-effect of this fixed bug: 6939196: method handle signatures off the boot class path get linkage errors The test case runs fine now.
13-05-2011