Java Code Examples for java.lang.reflect.Method.canAccess()

The following are Jave code examples for showing how to use canAccess() of the java.lang.reflect.Method class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: openjdk-jdk10   File: CanAccessTest.java   Source Code and License Vote up 5 votes
/**
 * null object parameter  for static members
 */
public void testStaticMember() throws Exception {
    Method m = Unsafe.class.getDeclaredMethod("throwIllegalAccessError");
    assertFalse(m.canAccess(null));
    assertTrue(m.trySetAccessible());

    try {
        // non-null object parameter
        m.canAccess(INSTANCE);
        assertTrue(false);
    } catch (IllegalArgumentException expected) { }
}
 
Example 2
Project: openjdk-jdk10   File: CanAccessTest.java   Source Code and License Vote up 5 votes
/**
 * the specified object must be an instance of the declaring class
 * for instance members
 */
public void testInstanceMethod() throws Exception {
    Method m = Unsafe.class.getDeclaredMethod("addressSize0");
    assertFalse(m.canAccess(INSTANCE));

    try {
        m.canAccess(null);
        assertTrue(false);
    } catch (IllegalArgumentException expected) { }
}
 
Example 3
Project: openjdk-jdk10   File: CanAccessTest.java   Source Code and License Vote up 5 votes
/**
 * the specified object must be an instance of the declaring class
 * for instance members
 */
public void testInvalidInstanceObject() throws Exception {
    Class<?> clazz = Class.forName("sun.security.x509.X500Name");
    Method m = clazz.getDeclaredMethod("size");

    try {
        m.canAccess(INSTANCE);
        assertTrue(false);
    } catch (IllegalArgumentException expected) { }
}