public void setAccessible (boolean accessible) { method.setAccessible(accessible); }
public static int getNextId(int type) throws Exception { if (method == null) { method = TraceObject.class.getDeclaredMethod("getNextId", int.class); method.setAccessible(true); } return (Integer) method.invoke(null, type); } }
@Override public Object run() { try { // Invoke the helper to load the native library, if succeed, then the native // library belong to the specified ClassLoader. Method method = helper.getMethod("loadLibrary", String.class, boolean.class); method.setAccessible(true); return method.invoke(null, name, absolute); } catch (Exception e) { return e; } } });
/** {@link BoundObjectTable#releaseMe} just cannot work the way we need it to. */ private void release() { try { Method release = BoundObjectTable.Table.class.getDeclaredMethod("release", String.class); release.setAccessible(true); release.invoke(boundObjectTable, boundId); } catch (Exception x) { LOG.log(Level.WARNING, "failed to unbind " + boundId, x); } }
/** * 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); } }
private Subscriber(EventBus bus, Object target, Method method) { this.bus = bus; this.target = checkNotNull(target); this.method = method; method.setAccessible(true); this.executor = bus.executor(); }
public static void callInjectViews(Object activity) { try { Class<?> viewMembersInjectorClass = Class.forName("roboguice.inject.ViewListener$ViewMembersInjector"); Method injectViewsMethod = viewMembersInjectorClass.getDeclaredMethod("injectViews", Object.class); injectViewsMethod.setAccessible(true); injectViewsMethod.invoke(null, activity); } catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | SecurityException | NoSuchMethodException e) { throw new RuntimeException("Could not invoke RoboGuice method!", e); } } }
private void initMethod() { Method[] methodsToExport = null; methodsToExport = this.serviceInterfaceClass.getMethods(); for (Method method : methodsToExport) { method.setAccessible(true); List<ProviderMethodModel> methodModels = methods.get(method.getName()); if (methodModels == null) { methodModels = new ArrayList<ProviderMethodModel>(1); methods.put(method.getName(), methodModels); } methodModels.add(new ProviderMethodModel(method, serviceName)); } }
private void initMethod() { Method[] methodsToExport = null; methodsToExport = this.serviceInterfaceClass.getMethods(); for (Method method : methodsToExport) { method.setAccessible(true); List<ProviderMethodModel> methodModels = methods.get(method.getName()); if (methodModels == null) { methodModels = new ArrayList<ProviderMethodModel>(1); methods.put(method.getName(), methodModels); } methodModels.add(new ProviderMethodModel(method, serviceName)); } }
public long getFixtureAddrB(Contact contact) { try { long addr =getContactAddr(contact); Method getFixtureB = contact.getClass().getDeclaredMethod("jniGetFixtureB", long.class); getFixtureB.setAccessible(true); return (Long) getFixtureB.invoke(contact, addr); } catch (Exception e) { e.printStackTrace(); return 0; } }
public long getFixtureAddrA(Contact contact) { try { long addr = getContactAddr(contact); Method getFixtureA = contact.getClass().getDeclaredMethod("jniGetFixtureA", long.class); getFixtureA.setAccessible(true); return (Long) getFixtureA.invoke(contact, addr); } catch (Exception e) { e.printStackTrace(); return 0; } }
private static Method init() { try { Method m = ClassLoader.class.getDeclaredMethod("findResource", String.class); m.setAccessible(true); return m; } catch (NoSuchMethodException e) { throw (Error)new NoSuchMethodError().initCause(e); } } }
public static Map<String, Method> getBeanPropertyReadMethods(Class cl) { Map<String, Method> properties = new HashMap<String, Method>(); for (; cl != null; cl = cl.getSuperclass()) { Method[] methods = cl.getDeclaredMethods(); for (Method method : methods) { if (isBeanPropertyReadMethod(method)) { method.setAccessible(true); String property = getPropertyNameFromBeanReadMethod(method); properties.put(property, method); } } } return properties; } }
public static Map<String, Method> getBeanPropertyReadMethods(Class cl) { Map<String, Method> properties = new HashMap<String, Method>(); for (; cl != null; cl = cl.getSuperclass()) { Method[] methods = cl.getDeclaredMethods(); for (Method method : methods) { if (isBeanPropertyReadMethod(method)) { method.setAccessible(true); String property = getPropertyNameFromBeanReadMethod(method); properties.put(property, method); } } } return properties; } }
private Throwable tryInternalFastPathGetFailure(Future<?> future) throws Exception { Method tryInternalFastPathGetFailureMethod = abstractFutureClass.getDeclaredMethod("tryInternalFastPathGetFailure"); tryInternalFastPathGetFailureMethod.setAccessible(true); return (Throwable) tryInternalFastPathGetFailureMethod.invoke(future); } }
@Override public Object invoke() throws Throwable { if (!Modifier.isPublic(origin.getDeclaringClass().getModifiers() & origin.getModifiers())) { origin.setAccessible(true); } selfCallInfo.set(instanceRef.get()); return tryInvoke(origin, instanceRef.get(), arguments); }
/** * Verifies that {@code method} produces a {@link NullPointerException} or {@link * UnsupportedOperationException} when the parameter in position {@code paramIndex} is null. If * this parameter is marked nullable, this method does nothing. * * @param instance the instance to invoke {@code method} on, or null if {@code method} is static */ public void testMethodParameter( @Nullable final Object instance, final Method method, int paramIndex) { method.setAccessible(true); testParameter(instance, invokable(instance, method), paramIndex, method.getDeclaringClass()); }
@SuppressWarnings("unchecked") public static <E extends Enum<E>> void checkEnum(Class<E> enumClass) { try { Method m = enumClass.getMethod("values"); m.setAccessible(true); Method e = enumClass.getMethod("valueOf", String.class); m.setAccessible(true); for (Enum<E> o : (Enum<E>[])m.invoke(null)) { assertSame(o, e.invoke(null, o.name())); } } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } }
@SuppressWarnings("unchecked") @Test public void hashSetCallableEnum() { // inlined TestHelper.checkEnum due to access restrictions try { Method m = Functions.HashSetCallable.class.getMethod("values"); m.setAccessible(true); Method e = Functions.HashSetCallable.class.getMethod("valueOf", String.class); e.setAccessible(true); for (Enum<HashSetCallable> o : (Enum<HashSetCallable>[])m.invoke(null)) { assertSame(o, e.invoke(null, o.name())); } } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } }
@SuppressWarnings("unchecked") @Test public void naturalComparatorEnum() { // inlined TestHelper.checkEnum due to access restrictions try { Method m = Functions.NaturalComparator.class.getMethod("values"); m.setAccessible(true); Method e = Functions.NaturalComparator.class.getMethod("valueOf", String.class); e.setAccessible(true); for (Enum<NaturalComparator> o : (Enum<NaturalComparator>[])m.invoke(null)) { assertSame(o, e.invoke(null, o.name())); } } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } }