Bug in catchException()

Attila Szegedi szegedia at gmail.com
Fri Sep 4 01:57:36 PDT 2009


Hi folks,

This small testcase fails in MethodHandles.catchException() on MLVM:

import java.dyn.MethodHandle;
import java.dyn.MethodHandles;
import java.dyn.MethodType;

public class TestCatchException
{
     public static void main(String[] args) throws Throwable
     {
         MethodHandle throwing = findStatic("throwing");
         MethodHandle catching = findStatic("catching");
         MethodHandles.catchException(throwing, MyException.class,
                 MethodHandles.dropArguments(catching, 0,
                         MyException.class));
     }

     private static class MyException extends RuntimeException
     {
     }

     private static MethodHandle findStatic(String name)
     {
         return MethodHandles.publicLookup().findStatic(
                 TestCatchException.class, name,  
MethodType.make(int.class,
                         Object.class));
     }


     public static int throwing(Object o)
     {
         throw new MyException();
     }

     public static int catching(Object o)
     {
         return 0;
     }
}

Notably, it fails with:

Exception in thread "main" java.dyn.NoAccessException: cannot access:  
*.java.dyn.MethodHandle.invoke(TestCatchException 
$MyException,java.lang.Object)int
	at sun.dyn.MemberName.newNoAccessException(MemberName.java:421)
	at sun.dyn.MemberName.newNoAccessException(MemberName.java:412)
	at sun.dyn.MemberName$Factory.resolveOrFail(MemberName.java:517)
	at java.dyn.MethodHandles$Lookup.findVirtual(MethodHandles.java:267)
	at sun.dyn.Invokers.exactInvoker(Invokers.java:66)
	at java.dyn.MethodHandles.exactInvoker(MethodHandles.java:761)
	at sun.dyn.FromGeneric.computeUnboxingInvoker(FromGeneric.java:137)
	at sun.dyn.FromGeneric.makeInstance(FromGeneric.java:160)
	at sun.dyn.FromGeneric.make(FromGeneric.java:174)
	at sun.dyn.MethodHandleImpl.convertArguments(MethodHandleImpl.java:460)
	at sun.dyn.MethodHandleImpl.makeGuardWithCatch(MethodHandleImpl.java: 
840)
	at java.dyn.MethodHandles.catchException(MethodHandles.java:1397)
	at TestCatchException.main(TestCatchException.java:12)

However, if I replace "MyException" with an exception on the boot  
classpath, i.e. IllegalArgumentException, then catchException() will  
succeed. Any advice for a workaround?

Attila.


More information about the mlvm-dev mailing list