public boolean isAccessible () { return method.isAccessible(); }
public boolean isAccessible () { return method.isAccessible(); }
/** * Make the given method accessible, explicitly setting it accessible if * necessary. The {@code setAccessible(true)} method is only called * when actually necessary, to avoid unnecessary conflicts with a JVM * SecurityManager (if active). * @param method the method to make accessible * @see java.lang.reflect.Method#setAccessible */ @SuppressWarnings("deprecation") // on JDK 9 public static void makeAccessible(Method method) { if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible()) { method.setAccessible(true); } }
/** * 设置方法为可访问 * * @param method 方法 * @return 方法 */ public static Method setAccessible(Method method) { if (null != method && false == method.isAccessible()) { method.setAccessible(true); } return method; }
/** * 设置方法为可访问 * * @param method 方法 * @return 方法 */ public static Method setAccessible(Method method) { if (null != method && false == method.isAccessible()) { method.setAccessible(true); } return method; }
@Override public Object run() { if (!m.isAccessible()) { m.setAccessible(true); } return m; } };
@Override public Object run() { if (!m.isAccessible()) { m.setAccessible(true); } return m; } };
public static boolean addApplicationListener(ApplicationContext applicationContext, ApplicationListener listener) { try { // backward compatibility to spring 2.0.1 Method method = applicationContext.getClass().getMethod("addApplicationListener", ApplicationListener.class); method.invoke(applicationContext, listener); return true; } catch (Throwable t) { if (applicationContext instanceof AbstractApplicationContext) { try { // backward compatibility to spring 2.0.1 Method method = AbstractApplicationContext.class.getDeclaredMethod("addListener", ApplicationListener.class); if (!method.isAccessible()) { method.setAccessible(true); } method.invoke(applicationContext, listener); return true; } catch (Throwable t2) { // ignore } } } return false; }
public static boolean addApplicationListener(ApplicationContext applicationContext, ApplicationListener listener) { try { // backward compatibility to spring 2.0.1 Method method = applicationContext.getClass().getMethod("addApplicationListener", ApplicationListener.class); method.invoke(applicationContext, listener); return true; } catch (Throwable t) { if (applicationContext instanceof AbstractApplicationContext) { try { // backward compatibility to spring 2.0.1 Method method = AbstractApplicationContext.class.getDeclaredMethod("addListener", ApplicationListener.class); if (!method.isAccessible()) { method.setAccessible(true); } method.invoke(applicationContext, listener); return true; } catch (Throwable t2) { // ignore } } } return false; }
/** * 改变private/protected的方法为可访问,尽量不进行改变,避免JDK的SecurityManager抱怨。 */ public static void makeAccessible(Method method) { if (!method.isAccessible() && (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))) { method.setAccessible(true); } }
private void makeAccessible(Method method) { if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible()) { method.setAccessible(true); } }
public static void makeAccessible(Method method) { if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible()) { method.setAccessible(true); } }
private static Object invoke(Method method, Object instance) { try { if (!method.isAccessible()) { setAccessible(method); } return method.invoke(instance); } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException( "Error checking value of member method " + method.getName() + " on " + method.getDeclaringClass(), e); } }
private static Object invoke(Method method, Object instance) { try { if (!method.isAccessible()) { setAccessible(method); } return method.invoke(instance); } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException( "Error checking value of member method " + method.getName() + " on " + method.getDeclaringClass(), e); } }
Object readResolve() { Class<?> clazz = _serialization.clazz; try { Method m = clazz.getDeclaredMethod(_serialization.name, _serialization.args); // 06-Oct-2012, tatu: Has "lost" its security override, may need to force back if (!m.isAccessible()) { ClassUtil.checkAndFixAccess(m, false); } return new AnnotatedMethod(null, m, null, null); } catch (Exception e) { throw new IllegalArgumentException("Could not find method '"+_serialization.name +"' from Class '"+clazz.getName()); } }
Object readResolve() { Class<?> clazz = _serialization.clazz; try { Method m = clazz.getDeclaredMethod(_serialization.name, _serialization.args); // 06-Oct-2012, tatu: Has "lost" its security override, may need to force back if (!m.isAccessible()) { ClassUtil.checkAndFixAccess(m, false); } return new AnnotatedMethod(null, m, null, null); } catch (Exception e) { throw new IllegalArgumentException("Could not find method '"+_serialization.name +"' from Class '"+clazz.getName()); } }
throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() + " has a onreturn callback config , but no such " + (onReturnMethod == null ? "method" : "instance") + " found. url:" + invoker.getUrl()); if (!onReturnMethod.isAccessible()) { onReturnMethod.setAccessible(true);
throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() + " has a onreturn callback config , but no such " + (onReturnMethod == null ? "method" : "instance") + " found. url:" + invoker.getUrl()); if (!onReturnMethod.isAccessible()) { onReturnMethod.setAccessible(true);
private void fireInvokeCallback(final Invoker<?> invoker, final Invocation invocation) { final ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = getAsyncMethodInfo(invoker, invocation); if (asyncMethodInfo == null) { return; } final Method onInvokeMethod = asyncMethodInfo.getOninvokeMethod(); final Object onInvokeInst = asyncMethodInfo.getOninvokeInstance(); if (onInvokeMethod == null && onInvokeInst == null) { return; } if (onInvokeMethod == null || onInvokeInst == null) { throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() + " has a oninvoke callback config , but no such " + (onInvokeMethod == null ? "method" : "instance") + " found. url:" + invoker.getUrl()); } if (!onInvokeMethod.isAccessible()) { onInvokeMethod.setAccessible(true); } Object[] params = invocation.getArguments(); try { onInvokeMethod.invoke(onInvokeInst, params); } catch (InvocationTargetException e) { fireThrowCallback(invoker, invocation, e.getTargetException()); } catch (Throwable e) { fireThrowCallback(invoker, invocation, e); } }
private void fireInvokeCallback(final Invoker<?> invoker, final Invocation invocation) { final ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = getAsyncMethodInfo(invoker, invocation); if (asyncMethodInfo == null) { return; } final Method onInvokeMethod = asyncMethodInfo.getOninvokeMethod(); final Object onInvokeInst = asyncMethodInfo.getOninvokeInstance(); if (onInvokeMethod == null && onInvokeInst == null) { return; } if (onInvokeMethod == null || onInvokeInst == null) { throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() + " has a oninvoke callback config , but no such " + (onInvokeMethod == null ? "method" : "instance") + " found. url:" + invoker.getUrl()); } if (!onInvokeMethod.isAccessible()) { onInvokeMethod.setAccessible(true); } Object[] params = invocation.getArguments(); try { onInvokeMethod.invoke(onInvokeInst, params); } catch (InvocationTargetException e) { fireThrowCallback(invoker, invocation, e.getTargetException()); } catch (Throwable e) { fireThrowCallback(invoker, invocation, e); } }