src/share/classes/sun/reflect/misc/MethodUtil.java

Print this page




  59         Class<?> clazz = m.getDeclaringClass();
  60         if (clazz.equals(AccessController.class) ||
  61             clazz.equals(Method.class) ||
  62             clazz.getName().startsWith("java.lang.invoke."))
  63             throw new InvocationTargetException(
  64                 new UnsupportedOperationException("invocation not supported"));
  65     }
  66 
  67     private static Object invoke(Method m, Object obj, Object[] params)
  68         throws InvocationTargetException, IllegalAccessException
  69     {
  70         ensureInvocableMethod(m);
  71         return m.invoke(obj, params);
  72     }
  73 }
  74 
  75 /*
  76  * Create a trampoline class.
  77  */
  78 public final class MethodUtil extends SecureClassLoader {
  79     private static String MISC_PKG = "sun.reflect.misc.";
  80     private static String TRAMPOLINE = MISC_PKG + "Trampoline";
  81     private static Method bounce = getTrampoline();
  82 
  83     private MethodUtil() {
  84         super();
  85     }
  86 
  87     public static Method getMethod(Class<?> cls, String name, Class<?>[] args)
  88         throws NoSuchMethodException {
  89         ReflectUtil.checkPackageAccess(cls);
  90         return cls.getMethod(name, args);
  91     }
  92 
  93     public static Method[] getMethods(Class<?> cls) {
  94         ReflectUtil.checkPackageAccess(cls);
  95         return cls.getMethods();
  96     }
  97 
  98     /*
  99      * Discover the public methods on public classes
 100      * and interfaces accessible to any caller by calling
 101      * Class.getMethods() and walking towards Object until




  59         Class<?> clazz = m.getDeclaringClass();
  60         if (clazz.equals(AccessController.class) ||
  61             clazz.equals(Method.class) ||
  62             clazz.getName().startsWith("java.lang.invoke."))
  63             throw new InvocationTargetException(
  64                 new UnsupportedOperationException("invocation not supported"));
  65     }
  66 
  67     private static Object invoke(Method m, Object obj, Object[] params)
  68         throws InvocationTargetException, IllegalAccessException
  69     {
  70         ensureInvocableMethod(m);
  71         return m.invoke(obj, params);
  72     }
  73 }
  74 
  75 /*
  76  * Create a trampoline class.
  77  */
  78 public final class MethodUtil extends SecureClassLoader {
  79     private static final String MISC_PKG = "sun.reflect.misc.";
  80     private static final String TRAMPOLINE = MISC_PKG + "Trampoline";
  81     private static final Method bounce = getTrampoline();
  82 
  83     private MethodUtil() {
  84         super();
  85     }
  86 
  87     public static Method getMethod(Class<?> cls, String name, Class<?>[] args)
  88         throws NoSuchMethodException {
  89         ReflectUtil.checkPackageAccess(cls);
  90         return cls.getMethod(name, args);
  91     }
  92 
  93     public static Method[] getMethods(Class<?> cls) {
  94         ReflectUtil.checkPackageAccess(cls);
  95         return cls.getMethods();
  96     }
  97 
  98     /*
  99      * Discover the public methods on public classes
 100      * and interfaces accessible to any caller by calling
 101      * Class.getMethods() and walking towards Object until