static Method getDeclaredMethod(final Class clazz, final String name,
            final Class[] types) throws NoSuchMethodException {
        if (System.getSecurityManager() == null)
            return clazz.getDeclaredMethod(name, types);
        else {
            try {
                return (Method) AccessController
                        .doPrivileged(new PrivilegedExceptionAction() {
                            public Object run() throws Exception {
                                return clazz.getDeclaredMethod(name, types);
                            }
                        });
            }
            catch (PrivilegedActionException e) {
                if (e.getCause() instanceof NoSuchMethodException)
                    throw (NoSuchMethodException) e.getCause();

                throw new RuntimeException(e.getCause());
            }
        }
    }