Example usage for java.lang.reflect Method setAccessible

List of usage examples for java.lang.reflect Method setAccessible

Introduction

In this page you can find the example usage for java.lang.reflect Method setAccessible.

Prototype

@Override
@CallerSensitive
public void setAccessible(boolean flag) 

Source Link

Usage

From source file:hivemall.dataset.LogisticRegressionDataGeneratorUDTFWrapper.java

@Override
protected CommandLine processOptions(ObjectInspector[] objectInspectors) throws UDFArgumentException {
    CommandLine commands = null;//from  ww  w  . j a  v a  2  s .  c  om
    try {
        Method m = udtf.getClass().getDeclaredMethod("processOptions");
        m.setAccessible(true);
        commands = (CommandLine) m.invoke(udtf, objectInspectors);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return commands;
}

From source file:dmh.kuebiko.view.NoteFrameTest.java

@Test
public void partialMatchSelectTabTest() {
    NoteManager noteMngr = new NoteManager(TestHelper.newDummyNoteDao());
    NoteStackFrame noteFrame = new NoteStackFrame(noteMngr);

    // Set focus on the search text field.
    noteFrame.searchText.requestFocus();
    // The first three characters of "Darth Vader".
    noteFrame.searchText.setText("Dar");
    // Simulate the user pressing the tab key, which will cause the search
    // text field to lose focus.
    try {//www.  ja  v  a  2s .c o m
        Method process = Component.class.getDeclaredMethod("processEvent", AWTEvent.class);
        process.setAccessible(true);
        process.invoke(noteFrame.searchText, new FocusEvent(noteFrame.searchText, FocusEvent.FOCUS_LOST));
    } catch (Exception e) {
        throw new TestException(e);
    }

    String noteText = trimToNull(noteFrame.notePanel.getHuxleyUiManager().getText());
    if (noteText == null) {
        System.out.println("SJKDFGHSDKFGKSDGFSDF");
    }
    Assert.assertNotNull(noteText, "The note text area should have text.");
}

From source file:org.piraso.server.spring.remoting.HttpInvokerReflectionHelper.java

private Method findMethod(String name, Class<?>... paramTypes) {
    Method method = ReflectionUtils.findMethod(clazz, name, paramTypes);
    method.setAccessible(true);

    return method;
}

From source file:de.tuberlin.uebb.jbop.access.ConstructorBuilderTest.java

private Object invoke(final Class<?> clazz, final String methodName, final Object object) throws Exception {
    final Method method = clazz.getDeclaredMethod(methodName, new Class<?>[] {});
    method.setAccessible(true);
    return method.invoke(object, new Object[] {});
}

From source file:com.netflix.evcache.pool.EVCacheClientPoolTest.java

@Test
public void selectClient_hugeNumOfModOps_noException() throws Exception {
    // Arrange/*from  ww  w .  jav  a  2  s. co  m*/

    // set up the object under test
    EVCacheNodeList evCacheNodeList = mock(EVCacheNodeList.class);
    EVCacheClientPoolManager evCacheClientPoolManager = mock(EVCacheClientPoolManager.class);

    EVCacheClientPool evCacheClientPool = new EVCacheClientPool("in a unit test", evCacheNodeList,
            (ThreadPoolExecutor) Executors.newFixedThreadPool(1), evCacheClientPoolManager);
    FieldUtils.writeField(evCacheClientPool, "numberOfModOps", new AtomicLong(0xFFFF_FFFF_FFFF_FFFFL), true);

    // Set up the method arguments
    EVCacheClient client1 = mock(EVCacheClient.class);
    EVCacheClient client2 = mock(EVCacheClient.class);
    List<EVCacheClient> clientsList = new ArrayList<>();
    clientsList.add(client1);
    clientsList.add(client2);

    // Ensure it's accessible
    // Yes it's private but this is a real bug we fixed.
    Method method = evCacheClientPool.getClass().getDeclaredMethod("selectClient", List.class);
    method.setAccessible(true);

    // Act
    Object ret = method.invoke(evCacheClientPool, clientsList);

    // Assert
    // The number set in numOfModOps should roll over to 0x1_0000_0000_0000_0000
    // so we should get client1 back
    EVCacheClient selected = (EVCacheClient) ret;
    assertSame(selected, client1);
}

From source file:org.easymock.itests.OsgiBaseTest.java

@Override
public void runBare() throws Throwable {
    // Since we are changing the bundles between the tests and that Spring is keeping a cache
    // of the OSGi platform once it is initialized, I'm using a secret method to shutdown
    // the platform between each test (this however slows down the tests so adding a wiser
    // cache is a good idea
    Method m = AbstractOsgiTests.class.getDeclaredMethod("shutdownTest");
    m.setAccessible(true);
    m.invoke(this);
    super.runBare();
}

From source file:com.collaide.fileuploader.helper.TestHelper.java

protected Method invokePrivateMethod(Class targetClass, String methodName, Class... argClasses)
        throws NoSuchMethodException {
    Method method = targetClass.getDeclaredMethod(methodName, argClasses);
    method.setAccessible(true);
    return method;

}

From source file:com.kibana.multitenancy.plugin.acl.SearchGuardACLRequestActionFilter.java

private boolean includesProperyValue(final IndicesRequest request, final String property,
        final String expValue) {
    try {/* w ww  .  j  a  v  a 2s. com*/
        final Method method = request.getClass().getDeclaredMethod(property);
        method.setAccessible(true);
        final String value = (String) method.invoke(request);
        return expValue.equals(value);
    } catch (final Exception e) {
        try {
            final Method method = request.getClass().getDeclaredMethod(property + "s");
            method.setAccessible(true);
            final String[] types = (String[]) method.invoke(request);
            return ArrayUtils.contains(types, expValue);
        } catch (final Exception e1) {
            logger.warn("Cannot determine {} for {} due to {}[s]() method not found", property, request,
                    property);
        }

    }
    return false;
}

From source file:com.conversantmedia.mapreduce.mrunit.UnitTestDistributedResourceManager.java

protected Object getBeanValue(String property, Object bean) {
    Object value = null;/*from w ww  . jav a  2 s .com*/
    String methodName = "get" + StringUtils.capitalize(property);
    try {
        Method method = bean.getClass().getDeclaredMethod(methodName);
        method.setAccessible(true);
        value = method.invoke(bean);
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
            | InvocationTargetException e) {
        logger().info("Unable to find method [" + methodName + "] for distributed resource.");
    }

    return value;
}

From source file:de.matzefratze123.heavyspleef.core.event.EventListenerMethod.java

@SuppressWarnings("unchecked")
public EventListenerMethod(Object instance, Method method) {
    this.instance = instance;
    this.method = method;

    if (!method.isAccessible()) {
        method.setAccessible(true);
    }/*from  w w w.ja v  a2s  . c  o  m*/

    Class<?>[] parameters = method.getParameterTypes();
    Validate.isTrue(parameters.length == 1,
            "method must have only one parameter which must be a subtype of GameEvent");

    Class<?> eventClass = parameters[0];
    Validate.isTrue(GameEvent.class.isAssignableFrom(eventClass),
            "First parameter of method must be a subtype of GameEvent");

    this.eventClass = (Class<? extends GameEvent>) eventClass;
}