Skip to content

Instantly share code, notes, and snippets.

@headius
Created May 14, 2011 15:41
Show Gist options
  • Save headius/972331 to your computer and use it in GitHub Desktop.
Save headius/972331 to your computer and use it in GitHub Desktop.
import java.lang.invoke.*;
public class BrokenCatchException {
public static Object catch8(Exception x, Object a, Object b, Object c, Object d, Object e, Object f, Object g, Object h) {
return null;
}
public static Object catch9(Exception x, Object a, Object b, Object c, Object d, Object e, Object f, Object g, Object h, Object i) {
return null;
}
public static Object target8(Object a, Object b, Object c, Object d, Object e, Object f, Object g, Object h) {
return null;
}
public static Object target9(Object a, Object b, Object c, Object d, Object e, Object f, Object g, Object h, Object i) {
return null;
}
public static void main(String[] args) {
try {
MethodHandles.Lookup lookup = MethodHandles.lookup();
// These first two scenarios work, with 8 args (9 in the handler)
MethodHandle target8 = MethodHandles.lookup().findStatic(BrokenCatchException.class, "target8", MethodType.methodType(Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class));
MethodHandle catch8 = MethodHandles.lookup().findStatic(BrokenCatchException.class, "catch8", MethodType.methodType(Object.class, Exception.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class));
MethodHandle works1 = MethodHandles.catchException(target8, Exception.class, catch8);
// This one fails, with 9 args (10 in the handler)
MethodHandle target9 = MethodHandles.lookup().findStatic(BrokenCatchException.class, "target9", MethodType.methodType(Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class));
MethodHandle catch9 = MethodHandles.lookup().findStatic(BrokenCatchException.class, "catch9", MethodType.methodType(Object.class, Exception.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class));
MethodHandle breaks = MethodHandles.catchException(target9, Exception.class, catch9);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment