Bug in catchException()
Attila Szegedi
szegedia at gmail.com
Wed Sep 9 00:01:30 PDT 2009
On 2009.09.09., at 0:15, John Rose wrote:
> The root cause is a known bug. One workaround is to put your app.
> classes on the boot CP. The bug happens when app. class names appear
> in signatures of methods referred to by direct MHs or by MH.invoke.
Yeah, I noticed that elsewhere too -- tried to get around the
java.lang.Object in place of receiver class returned from findVirtual/
unreflect by doing a convertArguments(), only to be surprised with
this exact exception when I passed thus converted MH back to some
other MethodHandles method (I think it was guardWithTest, doesn't
matter really). Sticking with Object receivers for now -- that's
actually not much of a problem.
As for this problem, I solved it by catching IllegalArgumentException,
eliminating dropArguments, and using a catch method that explicitly
receives the exception object in its parameter list, and does a check
on it, and if it ain't what it expected, rethrows it.
Attila.
> The 292 runtime shouldn't be using such a signature, I think, so
> there's another bug. Thanks for the report.
>
> -- John (on my iPhone)
>
> On Sep 4, 2009, at 1:57 AM, Attila Szegedi <szegedia at gmail.com> wrote:
>
>> 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