/** * Like Class#getMethod, but also returns non-public methods. Differs from * Class#getDeclaredMethod by also searching super classes. */ public static Method getAnyMethod(Class<?> clazz, String name, Class<?>... parameterTypes) throws NoSuchMethodException { try { // Because execute is protected, we cannot use getMethod. return clazz.getDeclaredMethod(name, parameterTypes); } catch (NoSuchMethodException e) { Class<?> superclass = clazz.getSuperclass(); if (superclass != null) { return getAnyMethod(superclass, name, parameterTypes); } throw e; } } }
@Override public void run() { Serializable result; try { result = execute(); } catch (Exception e) { try { Method method = ReflectionUtils.getAnyMethod(getClass(), "execute"); if (!ReflectionUtils.hasDeclaredException(method, e)) { LOGGER.error("Command failed due to a bug, please contact support@dcache.org.", e); e = new CommandPanicException("Command failed: " + e, e); } } catch (NoSuchMethodException suppressed) { e.addSuppressed(suppressed); } result = e; } reply(result); } }